pytest
pytest copied to clipboard
Fix terminal reporter output not appearing with capture active
Fixes #8973
When calling reporter.write() with flush=True during test execution,
the output was not appearing in the terminal because pytest's output
capture system intercepts writes to sys.stdout.
This fix duplicates stdout's file descriptor early in _prepareconfig(),
before any capture can start, and stores it in the config stash. The
terminal reporter then uses this duplicated FD to write directly to the
real terminal, bypassing capture.
The duplicated file is opened with line buffering and write_through mode to ensure immediate visibility of output.
Changes:
- src/_pytest/config/init.py: Add stdout FD duplication and stash key
- src/_pytest/terminal.py: Use duplicated FD in pytest_configure
- testing/test_terminal.py: Add regression test and fix incompatible tests
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]