[PATCH] run-tests: if ran outside of tests/, we should not search CWD for hg lib
Augie Fackler
raf at durin42.com
Fri Dec 8 14:45:30 EST 2017
> On Dec 7, 2017, at 21:46, matthieu.laneuville at octobus.net wrote:
>
> # HG changeset patch
> # User Matthieu Laneuville <matthieu.laneuville at octobus.net>
> # Date 1512650569 -32400
> # Thu Dec 07 21:42:49 2017 +0900
> # Node ID cd24cca4374384c80700782913c906c375d13e93
> # Parent af5507203d01d76ccb1d9ec04b1c9827d6017be9
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r cd24cca43743
> # EXP-Topic runtest-libfix
> run-tests: if ran outside of tests/, we should not search CWD for hg lib
>
> Since a18eef03d879, it is possible to start run-tests.py from another directory.
> If hg base folder is used, the local library is loaded preferentially which
> leads to an 'unexpected mercurial lib used' warning.
>
> This is because CWD is always prepended to PYPATH by default, which doesn't do
> anything, unless one happens to be in hg base directory. This patch insures that
> in a testing environment, CWD is removed from PYPATH, and the corresponding test
> was also updated.
I assume you mean that `pwd` is implicitly on sys.path, right? Not that run-tests is doing something to add `pwd` to sys.path via PYTHONPATH?
>
> diff -r af5507203d01 -r cd24cca43743 hg
> --- a/hg Sun Oct 15 18:02:11 2017 +0200
> +++ b/hg Thu Dec 07 21:42:49 2017 +0900
> @@ -27,6 +27,11 @@ if libdir != '@' 'LIBDIR' '@':
> libdir = os.path.abspath(libdir)
> sys.path.insert(0, libdir)
>
> +# if called by run-tests, make sure we don't import CWD hg by mistake
> +if os.environ.get('TESTDIR', False):
> + if sys.path[0] == os.path.dirname(os.path.abspath(__file__)):
> + sys.path.remove(sys.path[0])
Yikes. This feels like the wrong fix, as you're now modifying the globally-installed hg stub to be aware of the test runner.
> +
> # enable importing on demand to reduce startup time
> try:
> if sys.version_info[0] < 3 or sys.version_info >= (3, 6):
> diff -r af5507203d01 -r cd24cca43743 tests/run-tests.py
> --- a/tests/run-tests.py Sun Oct 15 18:02:11 2017 +0200
> +++ b/tests/run-tests.py Thu Dec 07 21:42:49 2017 +0900
> @@ -2898,7 +2898,13 @@ class TestRunner(object):
> if self._hgpath is not None:
> return self._hgpath
>
> - cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"'
> + # if run from somewhere else than tests/, avoid searching CWD for hg lib
> + if os.getcwd() != os.path.dirname(os.path.abspath(__file__)):
> + cmd = b'%s -c "import sys; sys.path.remove(\'\'); ' \
> + 'import mercurial; print (mercurial.__path__[0])"'
> + else:
> + cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"'
> +
> cmd = cmd % PYTHON
> if PYTHON3:
> cmd = _strpath(cmd)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list