Skip to content

Fix capteesys producing doubled output with --capture=no#14205

Open
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Fridayai700:fix-capteesys-double-output
Open

Fix capteesys producing doubled output with --capture=no#14205
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Fridayai700:fix-capteesys-double-output

Conversation

@Fridayai700
Copy link

Fixes #13784.

Summary

When capteesys is used with -s (--capture=no), every print() call produces doubled output on the terminal.

Root cause: TeeCaptureIO.write() tees output to the original stream in real-time. On CaptureFixture.close(), pop_outerr_to_orig() calls writeorg() which writes the same buffered content to the original stream a second time.

With other capture modes (e.g. --capture=fd), the "original stream" that writeorg() targets is the global capture's pipe — so the double write is absorbed correctly. With --capture=no, there is no global capture, so writeorg() writes directly to the real terminal, producing the duplicate.

Fix: When tee is enabled, use readouterr() instead of pop_outerr_to_orig() in close(), since the output was already delivered live by TeeCaptureIO.

Test plan

  • Added test_capteesys_no_double_output_with_capture_no that verifies output appears exactly once when using capteesys with -s
  • All 27 existing TestCaptureFixture tests pass

When capteesys is used with -s (--capture=no), output was printed
twice: once by TeeCaptureIO teeing to the original stream in
real-time, and again by pop_outerr_to_orig() writing the buffered
content back via writeorg() on close.

Skip the writeorg() call when tee is enabled, since the output was
already delivered live.

Fixes pytest-dev#13784.
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inclusion of capteesys in pytest function and run with -s causes doubled prints to stdout

2 participants

Comments