diff tests/run-tests.py @ 52008:d7e9503c07d2

run-tests: include non-activated venv packages in `PYTHONPATH` If a venv is activated since afa9d73780e1, `hghave` would see the packages installed in it, and enable related tests. If the python interpreter was launched directly however, none of them were seen. In addition to getting consistent behavior, it's also easier to manage in CI if the venv doesn't need activation.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 11 Oct 2024 00:56:20 -0400
parents daeb85ebee48
children 6f7cc970bfda
line wrap: on
line diff
--- a/tests/run-tests.py	Thu Oct 10 17:52:26 2024 -0400
+++ b/tests/run-tests.py	Fri Oct 11 00:56:20 2024 -0400
@@ -3358,14 +3358,15 @@
 
         # Setting PYTHONPATH with an activated venv causes the modules installed
         # in it to be ignored.  Therefore, include the related paths in sys.path
-        # in PYTHONPATH.
-        virtual_env = osenvironb.get(b"VIRTUAL_ENV")
-        if virtual_env:
-            virtual_env = os.path.join(virtual_env, b'')
-            for p in sys.path:
-                p = _sys2bytes(p)
-                if p.startswith(virtual_env):
-                    pypath.append(p)
+        # in PYTHONPATH.  If the executable is run directly without activation,
+        # any modules installed in it would also be ignored, so include them for
+        # the same reason.
+
+        for p in sys.path:
+            if p.startswith(sys.exec_prefix):
+                path = _sys2bytes(p)
+                if path not in pypath:
+                    pypath.append(path)
 
         # We have to augment PYTHONPATH, rather than simply replacing
         # it, in case external libraries are only available via current