fix dash test runner
This commit is contained in:
@@ -57,6 +57,7 @@ DEFAULT_MAX_LOG_LINES = 4000
|
||||
_MAX_LINE_CHARS = 4000
|
||||
DEFAULT_COLLECT_TIMEOUT = 120.0
|
||||
DEFAULT_RUN_TIMEOUT = 1800.0
|
||||
PYTHON_ENV_VAR = "MESHNET_PYTHON"
|
||||
|
||||
_NODE_ID_RE = re.compile(r"^[\w./\[\]:,= @-]+$")
|
||||
|
||||
@@ -98,6 +99,23 @@ def _real_inference_enabled() -> bool:
|
||||
return os.environ.get(REAL_INFERENCE_ENV_VAR) == "1"
|
||||
|
||||
|
||||
def _test_python() -> str:
|
||||
"""Return the project interpreter configured by the machine env file.
|
||||
|
||||
The tracker may run from a lightweight service environment while the test
|
||||
suite needs the project's full environment (including SDK dependencies).
|
||||
``meshnet_tracker.cli`` loads ``.env.<hostname>`` before constructing the
|
||||
server, so use its explicit interpreter selection for child pytest runs.
|
||||
Direct users of ``TestRunManager`` retain the normal interpreter fallback.
|
||||
"""
|
||||
configured = os.environ.get(PYTHON_ENV_VAR, "").strip()
|
||||
if configured:
|
||||
python = Path(configured).expanduser()
|
||||
if python.is_file() and os.access(python, os.X_OK):
|
||||
return str(python)
|
||||
return sys.executable
|
||||
|
||||
|
||||
class TestRunManager:
|
||||
"""Collects pytest node IDs and runs one fixed target at a time."""
|
||||
|
||||
@@ -145,7 +163,7 @@ class TestRunManager:
|
||||
if self._collected_at is not None and not refresh:
|
||||
return self._collection_snapshot_locked()
|
||||
|
||||
cmd = [sys.executable, "-m", "pytest", "--collect-only", "-q", "-p", "no:cacheprovider"]
|
||||
cmd = [_test_python(), "-m", "pytest", "--collect-only", "-q", "-p", "no:cacheprovider"]
|
||||
if not _real_inference_enabled():
|
||||
for name in sorted(
|
||||
p.name for p in (self.repo_root / "tests").glob("test_real_*.py")
|
||||
@@ -216,7 +234,7 @@ class TestRunManager:
|
||||
with self._lock:
|
||||
if self._run is not None and self._run["status"] == "running":
|
||||
raise RunInProgressError("a test run is already in progress")
|
||||
cmd = [sys.executable, "-m", "pytest", "-q", "-p", "no:cacheprovider", *pytest_args]
|
||||
cmd = [_test_python(), "-m", "pytest", "-q", "-p", "no:cacheprovider", *pytest_args]
|
||||
self._stdout = deque(maxlen=self.max_log_lines)
|
||||
self._stderr = deque(maxlen=self.max_log_lines)
|
||||
process = subprocess.Popen( # noqa: S603 — fixed argv, no shell
|
||||
|
||||
Reference in New Issue
Block a user