[PATCH 072 of 179 tests-refactor] run-tests: move pypath manipulation into TestRunner

Gregory Szorc gregory.szorc at gmail.com
Fri May 2 18:38:29 UTC 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1398012868 25200
#      Sun Apr 20 09:54:28 2014 -0700
# Branch stable
# Node ID 37dced6af8bec7f3957ba90fa7245c97224b3412
# Parent  567c0c494aee7ce33ed3b82127ed84854e7b9216
run-tests: move pypath manipulation into TestRunner

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1019,16 +1019,33 @@ class TestRunner(object):
         oldenv = dict(os.environ)
         try:
             return self._run(tests)
         finally:
             os.environ.clear()
             os.environ.update(oldenv)
 
     def _run(self, tests):
+        # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
+        # can run .../tests/run-tests.py test-foo where test-foo
+        # adds an extension to HGRC. Also include run-test.py directory to
+        # import modules like heredoctest.
+        pypath = [self.pythondir, self.testdir,
+                  os.path.abspath(os.path.dirname(__file__))]
+        # We have to augment PYTHONPATH, rather than simply replacing
+        # it, in case external libraries are only available via current
+        # PYTHONPATH.  (In particular, the Subversion bindings on OS X
+        # are in /opt/subversion.)
+        oldpypath = os.environ.get(IMPL_PATH)
+        if oldpypath:
+            pypath.append(oldpypath)
+        os.environ[IMPL_PATH] = os.pathsep.join(pypath)
+
+        self.coveragefile = os.path.join(self.testdir, '.coverage')
+
         vlog("# Using TESTDIR", self.testdir)
         vlog("# Using HGTMP", self.hgtmp)
         vlog("# Using PATH", os.environ["PATH"])
         vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
 
         try:
             return self._runtests(tests) or 0
         finally:
@@ -1444,29 +1461,12 @@ def main(args, runner=None, parser=None)
     os.environ["BINDIR"] = runner.bindir
     os.environ["PYTHON"] = PYTHON
 
     path = [runner.bindir] + os.environ["PATH"].split(os.pathsep)
     if runner.tmpbindir != runner.bindir:
         path = [runner.tmpbindir] + path
     os.environ["PATH"] = os.pathsep.join(path)
 
-    # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
-    # can run .../tests/run-tests.py test-foo where test-foo
-    # adds an extension to HGRC. Also include run-test.py directory to import
-    # modules like heredoctest.
-    pypath = [runner.pythondir, runner.testdir,
-              os.path.abspath(os.path.dirname(__file__))]
-    # We have to augment PYTHONPATH, rather than simply replacing
-    # it, in case external libraries are only available via current
-    # PYTHONPATH.  (In particular, the Subversion bindings on OS X
-    # are in /opt/subversion.)
-    oldpypath = os.environ.get(IMPL_PATH)
-    if oldpypath:
-        pypath.append(oldpypath)
-    os.environ[IMPL_PATH] = os.pathsep.join(pypath)
-
-    runner.coveragefile = os.path.join(runner.testdir, ".coverage")
-
     return runner.run(tests)
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))



More information about the Mercurial-devel mailing list