test(update): venv-holder live E2E spawns the foreign python from outside the venv
Since 7a94b1fbf7 project_venv_dir resolves .venv, and the wine2e runner's
`uv run` interpreter lives in the checkout's .venv, so a sys.executable child
is a venv holder by design and test_foreign_python_not_detected failed on
every wine2e push (baseline run 35427256445 on origin/main). Use the base
interpreter the venv was created from as the foreign python; skip when the
runner has none outside the venv.
This commit is contained in:
@@ -40,7 +40,7 @@ pytestmark = [
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def _spawn(args: list[str], cwd: Path | None = None) -> subprocess.Popen:
|
||||
def _spawn(args: list[str], cwd: Path | None = None, python: str | None = None) -> subprocess.Popen:
|
||||
"""Spawn a real sleeper process whose argv carries the given tail.
|
||||
|
||||
``python -c "sleep" <tail...>`` — the tail is inert data to the child
|
||||
@@ -48,7 +48,7 @@ def _spawn(args: list[str], cwd: Path | None = None) -> subprocess.Popen:
|
||||
code classifies on.
|
||||
"""
|
||||
proc = subprocess.Popen(
|
||||
[sys.executable, "-c", "import time; time.sleep(300)", *args],
|
||||
[python or sys.executable, "-c", "import time; time.sleep(300)", *args],
|
||||
cwd=str(cwd or PROJECT_ROOT),
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
@@ -89,12 +89,26 @@ class TestDetection:
|
||||
_kill(proc)
|
||||
|
||||
def test_foreign_python_not_detected(self):
|
||||
"""A python process with no Hermes argv and cwd OUTSIDE the install
|
||||
must not be reported as a holder."""
|
||||
"""A python process with no Hermes argv, cwd OUTSIDE the install AND an
|
||||
interpreter outside the project venv must not be reported as a holder.
|
||||
|
||||
``sys.executable`` is the wrong sleeper here: the runner's ``uv run`` interpreter
|
||||
lives in the checkout's ``.venv``, which ``project_venv_dir`` resolves since
|
||||
7a94b1fbf77, so a ``sys.executable`` child IS a venv holder by design. The base
|
||||
interpreter the venv was created from is the foreign python."""
|
||||
import tempfile
|
||||
|
||||
from hermes_constants import project_venv_dir
|
||||
|
||||
base = getattr(sys, "_base_executable", None) or sys.executable
|
||||
venv_dir = project_venv_dir(PROJECT_ROOT)
|
||||
if venv_dir is not None and str(Path(base).resolve()).lower().startswith(
|
||||
str(venv_dir.resolve()).lower()
|
||||
):
|
||||
pytest.skip("no interpreter outside the project venv available on this runner")
|
||||
|
||||
outside = Path(tempfile.mkdtemp())
|
||||
proc = _spawn(["totally", "unrelated"], cwd=outside)
|
||||
proc = _spawn(["totally", "unrelated"], cwd=outside, python=base)
|
||||
try:
|
||||
pids = [pid for pid, _, _ in _detect()]
|
||||
assert proc.pid not in pids
|
||||
|
||||
Reference in New Issue
Block a user