Ned Batchelder  committed 811ed58

The current directory auto-inserted into sys.path is now absolute, to better mimic Python execution.

  • Participants
  • Parent commits cdc34b7
  • Branches default

Comments (0)

Files changed (3)

 - Modules can now be run directly using ``coverage run -m modulename``, to
   mirror Python's ``-m`` flag.  Closes `issue 95`_, thanks, Brandon Rhodes.
+- ``coverage run`` didn't emulate Python accurately in one detail: the
+  current directory inserted into ``sys.path`` was relative rather than
+  absolute. This is now fixed.
 - A little bit of Jython support: `coverage run` can now measure Jython
   execution by adapting when $py.class files are traced. Thanks, Adi Roiban.

File coverage/

     old_argv = sys.argv
     old_path0 = sys.path[0]
     sys.argv = args
-    sys.path[0] = os.path.dirname(filename)
+    sys.path[0] = os.path.abspath(os.path.dirname(filename))
         # Open the source file.

File test/

 sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
 from coveragetest import CoverageTest
+here = os.path.dirname(__file__)
 class ProcessTest(CoverageTest):
     """Tests of the per-process behavior of"""
         self.assertEqual(status, status2)
         self.assertEqual(status, 0)
+    def test_coverage_run_is_like_python(self):
+        tryfile = os.path.join(here, "")
+        self.make_file("", open(tryfile).read())
+        out = self.run_command("coverage run")
+        out2 = self.run_command("python")
+        self.assertMultiLineEqual(out, out2)
     if hasattr(os, 'fork'):
         def test_fork(self):