# HG changeset patch # User Pierre-Yves David # Date 1736150034 -3600 # Node ID 69b64f8da6cd0104d76fe2e8810f907a6c4252d5 # Parent c7674da2f7eab8b1cb5cfe7eb2186ca82ac362b5 run-tests: lean more on the virtual env binary when we use one The virtual env is already providing use with a correct `python` and `python3` executable, so lets not add more complexity in the case were we can simply rely on them. diff -r c7674da2f7ea -r 69b64f8da6cd tests/run-tests.py --- a/tests/run-tests.py Tue Dec 31 01:42:01 2024 +0100 +++ b/tests/run-tests.py Mon Jan 06 08:53:54 2025 +0100 @@ -3757,7 +3757,17 @@ def _usecorrectpython(self): """Configure the environment to use the appropriate Python in tests.""" # Tests must use the same interpreter as us or bad things will happen. - pyexe_names = [b'python', b'python3'] + + # install dir != None means we did install mercurial within a temporary + # virtual env and do need to make sure the right python will be in + # front of the PATH. Except for Windows who lack a `python3` executable + # in this case. + if self._installdir is None: + pyexe_names = [b'python', b'python3'] + elif WINDOWS: + pyexe_names = [b'python3'] + else: + return # os.symlink() is a thing with py3 on Windows, but it requires # Administrator rights. @@ -3818,6 +3828,7 @@ def _use_correct_mercurial(self): target_exec = os.path.join(self._custom_bin_dir, b'hg') + # hgcommand is ≠ hg in case like `rhg` and `chg` or with windows .exe's if self._hgcommand != b'hg': real_exec = shutil.which(self._hgcommand) if real_exec is None: @@ -3825,6 +3836,10 @@ if real_exec == target_exec: # do not overwrite something with itself return + if os.path.exists(target_exec): + # there is already something at the destination. Let's not + # overwrite it. + return if WINDOWS: with open(target_exec, 'wb') as f: f.write(b'#!/bin/sh\n')