[PATCH] tests: add a flag for adding other things into tests python path

Mateusz Kwapich mitrandir at fb.com
Wed Mar 30 17:32:56 EDT 2016


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1459373177 25200
#      Wed Mar 30 14:26:17 2016 -0700
# Node ID e01dd6e1427d0696def2151d3bd9581d83d78a63
# Parent  479707ded4d0b07347f5b98982a0fca8a94dcf98
tests: add a flag for adding other things into tests python path

This is very useful for testing extensions that depend on other extensions. Until
now run-tests picked the systemwide installed version of the dependencies and
we had no way to point it to the other version checked out locally in different
dir.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -265,6 +265,8 @@ def getparser():
                            " (TEMPORARY)")
     parser.add_option('--extra-config-opt', action="append",
                       help='set the given config opt in the test hgrc')
+    parser.add_option('--dep-dir', action="append",
+                      help='add an extra directory to python path')
     parser.add_option('--random', action="store_true",
                       help='run tests in random order')
     parser.add_option('--profile-runner', action='store_true',
@@ -1923,6 +1925,7 @@ class TestRunner(object):
         self._bindir = None
         self._tmpbinddir = None
         self._pythondir = None
+        self._depdirs = []
         self._coveragefile = None
         self._createdfiles = []
         self._hgcommand = None
@@ -2029,6 +2032,8 @@ class TestRunner(object):
         self._hgtmp = osenvironb[b'HGTMP'] = (
             os.path.realpath(tmpdir))
 
+        if self.options.dep_dir:
+            self._depdirs.extend(map(os.path.abspath,self.options.dep_dir))
         if self.options.with_hg:
             self._installdir = None
             whg = self.options.with_hg
@@ -2092,7 +2097,7 @@ class TestRunner(object):
         # 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, runtestdir]
+        pypath = self._depdirs + [self._pythondir, self._testdir, runtestdir]
         # 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


More information about the Mercurial-devel mailing list