diff --git a/tests/test_cleanup.py b/tests/test_cleanup.py index 16256998..084c5dc1 100644 --- a/tests/test_cleanup.py +++ b/tests/test_cleanup.py @@ -2,7 +2,6 @@ artifact trim, and the `clean` CLI command.""" import argparse -import subprocess from conftest import install_bmad_config, machine_json @@ -21,12 +20,6 @@ def _state_run(project, run_id, **kw): return run_dir -def _dead_pid() -> int: - p = subprocess.Popen(["true"]) - p.wait() - return p.pid - - # --------------------------------------------------------------- predicates diff --git a/tests/test_runs.py b/tests/test_runs.py index badffe78..ca1f6f26 100644 --- a/tests/test_runs.py +++ b/tests/test_runs.py @@ -405,12 +405,17 @@ def test_stop_run_dead_pid_falls_back(tmp_path, monkeypatch): def test_stop_run_signals_live_process(tmp_path, monkeypatch): monkeypatch.setattr(runs, "kill_session", lambda _rid: None) run_dir = _make_state_run(tmp_path, "r1") - proc = subprocess.Popen(["sleep", "30"]) - (run_dir / "engine.pid").write_text(str(proc.pid)) - assert runs.stop_run(run_dir) is True - # the process received SIGTERM and is gone - assert proc.poll() is not None or proc.wait(timeout=5) is not None - assert load_state(run_dir).stopped is True + proc = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(30)"]) + try: + (run_dir / "engine.pid").write_text(str(proc.pid)) + assert runs.stop_run(run_dir) is True + # the process received SIGTERM and is gone + assert proc.poll() is not None or proc.wait(timeout=5) is not None + assert load_state(run_dir).stopped is True + finally: + if proc.poll() is None: + proc.kill() + proc.wait(timeout=10) def test_stop_run_respects_engine_written_stopped(tmp_path, monkeypatch):