Mercurial > forks > mercurial
changeset 53277:3c04ec0aa369 stable
run-tests: stop relying on Mercurial being configured on the system
This likely hasn't been seen in the wild because most developers will have
configured their system to have a username and editor (and POSIX CI systems
likely have `USER` set in the environment by default, along with `vi` installed).
The problem is if `--local` is not passed, an `hg debuginstall` command is run
to find the installed library modules. Inside the Windows Docker image, neither
the user nor the editor is configured, and the fallback `notepad.exe` isn't
installed at all. Both of these conditions are noticed by the command, which
exits with the total error count, and `run-tests.py` dutifully ignores the
(valid) path that it asked for, and reports:
fatal: fetching library from `hg` failed with 2:
C:\hgdev\tmp\hgtests.hc2n7chg\install\lib\site-packages\mercurial
It would be nice to not have `debuginstall` yell about things not asked of it,
because I've hit this issue before in other contexts. But that looks
complicated, and I don't need another side project that's only usable after the
next release. The system environment shouldn't influence the tests at all.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 09 May 2025 12:44:46 -0400 |
parents | 751c01d7eff9 |
children | 2af8c5560b99 |
files | tests/run-tests.py |
diffstat | 1 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/run-tests.py Thu May 15 21:03:36 2025 -0400 +++ b/tests/run-tests.py Fri May 09 12:44:46 2025 -0400 @@ -4014,6 +4014,19 @@ sys.stderr.write(err) sys.exit(3) + @staticmethod + def _get_debuginstall_env(): + """return the environment to run ``hg debuginstall`` safely""" + # The debuginstall command checks a bunch of things, and exits with the + # number of errors encountered, even if -T is passed and the template + # didn't ask for things related to the error(s). Supply a fallback so + # that running tests without --local doesn't hinge on Mercurial being + # configured on the current system. + env = os.environ.copy() + env["HGUSER"] = "test_gremlin" + env["HGEDITOR"] = sys.executable # The executable must exist + return env + def _get_hg_module_policy(self): """return the module policy as seen by the "hg" binary""" cmd = [ @@ -4027,6 +4040,7 @@ stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, + env=self._get_debuginstall_env(), ) out, err = p.communicate() if p.returncode != 0: @@ -4053,6 +4067,7 @@ stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, + env=self._get_debuginstall_env(), ) out, err = p.communicate() if p.returncode != 0: @@ -4172,7 +4187,12 @@ sys.exit(1) cmd = _bytes2sys(b"%s debuginstall -Tjson" % self._hgcommand) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + p = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + shell=True, + env=self._get_debuginstall_env(), + ) out, err = p.communicate() props = json.loads(out)[0]