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>
from pathlib import Path
+import sys
+
SYSTEM_TEST_DIR_GIT_PATH = "bin/tests/system"
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