changeset 52616:69b64f8da6cd

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 06 Jan 2025 08:53:54 +0100
parents c7674da2f7ea
children 87ceb51d124c
files tests/run-tests.py
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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')