From: Nicki Křížek Date: Wed, 15 Apr 2026 08:08:01 +0000 (+0000) Subject: Use virtualenv's Python interpreter when running tests from a venv X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68cfca178850fde0139906e61bce454412818d6b;p=thirdparty%2Fbind9.git Use virtualenv's Python interpreter when running tests from a venv 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 --- diff --git a/bin/tests/system/isctest/vars/build.py b/bin/tests/system/isctest/vars/build.py index 18ceca9a00b..e8978d088d7 100644 --- a/bin/tests/system/isctest/vars/build.py +++ b/bin/tests/system/isctest/vars/build.py @@ -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