From 9463d53763dee0ff75233206f704ea2644be4387 Mon Sep 17 00:00:00 2001 From: James Smith Date: Thu, 11 Jun 2026 16:48:13 +0100 Subject: [PATCH] test: address review feedback on fake_process fixture - document str defaults / bytes for binary-mode callers - wire __exit__ to False so exceptions are not suppressed - exercise exited-process path through subprocess.run Co-Authored-By: Claude Fable 5 --- tests/conftest.py | 3 +++ tests/test_conftest_fixtures.py | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6a72b6f..33e9431 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -147,6 +147,8 @@ def fake_process(): Hand-rolled Popen mocks keep missing two things: __enter__ (subprocess.run wraps Popen in a context manager) and a communicate() tuple. Use this factory instead of building MagicMock processes inline. + + Defaults are str (for text=True subprocesses); pass bytes explicitly for binary-mode callers. """ def _make(returncode=0, stdout="", stderr="", running=True, pid=12345): @@ -160,6 +162,7 @@ def fake_process(): proc.stderr.read.return_value = stderr proc.stdin = MagicMock() proc.__enter__.return_value = proc + proc.__exit__.return_value = False return proc return _make diff --git a/tests/test_conftest_fixtures.py b/tests/test_conftest_fixtures.py index 5b4e7fe..16847c7 100644 --- a/tests/test_conftest_fixtures.py +++ b/tests/test_conftest_fixtures.py @@ -18,7 +18,10 @@ class TestFakeProcess: assert proc.pid == 12345 assert proc.communicate() == ("", "") - def test_exited_process(self, fake_process): - proc = fake_process(running=False, returncode=1, stderr=b"device busy") - assert proc.poll() == 1 - assert proc.stderr.read() == b"device busy" + def test_exited_process_detected_via_run(self, fake_process): + """An exited process's returncode and stderr surface through subprocess.run.""" + proc = fake_process(running=False, returncode=1, stdout=b"", stderr=b"device busy") + with patch("subprocess.Popen", return_value=proc): + result = subprocess.run(["anything"], capture_output=True) + assert result.returncode == 1 + assert result.stderr == b"device busy"