]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use virtualenv's Python interpreter when running tests from a venv
authorNicki Křížek <nicki@isc.org>
Wed, 15 Apr 2026 08:08:01 +0000 (08:08 +0000)
committerNicki Křížek <nicki@isc.org>
Wed, 15 Apr 2026 12:26:35 +0000 (14:26 +0200)
Meson bakes the absolute path of the detected Python binary (e.g.
/usr/bin/python3.12) into the PYTHON build variable. When tests are run
from a virtualenv, that stored path might point to the system Python
which lacks the virtualenv's installed packages, causing test failures.

Fix this by checking whether the current process is running inside a
virtualenv (sys.prefix != sys.base_prefix) and, if so, replacing the
stored PYTHON build var with sys.executable — the interpreter that is
already running pytest and has all required dependencies available.

The behaviour on EL8/EL9 (where meson prefers python3.12 over the older
platform default) and on FreeBSD (python3.11) is unchanged, since those
workflows run pytest without an active virtualenv in our CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bin/tests/system/isctest/vars/build.py

index 18ceca9a00b5cb6289443dc79e96ac8c3cbaa7d1..e8978d088d760e6ee86b141d4f7dfc32ec31b44c 100644 (file)
@@ -11,6 +11,8 @@
 
 from pathlib import Path
 
+import sys
+
 SYSTEM_TEST_DIR_GIT_PATH = "bin/tests/system"
 
 
@@ -53,6 +55,17 @@ def load_vars_from_build_files() -> dict[str, str]:
         if var_file.exists():
             build_vars[var] = var_file.read_text(encoding="utf-8").strip()
 
+    # When running inside a virtualenv, prefer the virtualenv's interpreter
+    # over the path baked in by meson.
+    # This is needed because meson is configured to prefer specific versions
+    # (e.g. python3.12 and python3.11) by default to properly detect the
+    # right python interpreter in CI - this is undesirable when running
+    # in a virtualenv as it can lead to the system tests using the system
+    # versions of Python dependencies defeating the purpose of the virtual
+    # environment.
+    if sys.prefix != sys.base_prefix:
+        build_vars["PYTHON"] = sys.executable
+
     return build_vars