From 562d0d7087e43e07c5af4de4348261de82cabfad Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 2 Nov 2026 09:50:41 -0500 Subject: [PATCH] Flush the real streams before each B0.2 test captures output pytest-split writes its header to sys.stdout through the terminal writer and doesn't flush it when stdout is a pipe, as it is in CI. The B0.2 script's _flush_streams flushes sys.__stdout__, so the first test in a shard that runs it under capfd captured the header and failed its empty-output assertion. That test is test_a_failure_from_outside_this_script_prints_no_value. An autouse fixture now flushes sys.__stdout__ and sys.__stderr__ before each test in the module, so no earlier writer's text reaches a test's capture. The fixture adds no tests, so the tier files don't change. Co-Authored-By: Claude Opus 5.5 --- tests/test_track_b_b0_2_counts.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_track_b_b0_2_counts.py b/tests/test_track_b_b0_2_counts.py index f3d3da05..46e308de 100644 --- a/tests/test_track_b_b0_2_counts.py +++ b/tests/test_track_b_b0_2_counts.py @@ -53,6 +53,17 @@ ) +@pytest.fixture(autouse=True) +def _flush_the_real_streams(): + """Flush Python's original stdout and stderr before each test captures + anything. A plugin can leave text in them unflushed, as pytest-split + leaves its header when stdout is a pipe, and the script's own flush in + ``_flush_streams`` would then push that text into the test's ``capfd``.""" + for stream in (sys.__stdout__, sys.__stderr__): + if stream is not None: + stream.flush() + + def _row( person, wave=2011,