Skip to content

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

Merged
Pierre-Sassoulas merged 5 commits into
pytest-dev:mainfrom
worksbyfriday:fix-capteesys-double-output
May 23, 2026
Merged

Fix capteesys producing doubled output with --capture=no#14205
Pierre-Sassoulas merged 5 commits into
pytest-dev:mainfrom
worksbyfriday:fix-capteesys-double-output

Conversation

@worksbyfriday
Copy link
Copy Markdown
Contributor

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
@Pierre-Sassoulas
Copy link
Copy Markdown
Member

Pierre-Sassoulas commented May 23, 2026

Hey @worksbyfriday, it seems the CI isn't green anymore using latest main, would you mind looking into it, please ? (nvm it's probably my fault for merging #14210 without a rebase)

@Pierre-Sassoulas Pierre-Sassoulas merged commit 46ea2a3 into pytest-dev:main May 23, 2026
60 of 62 checks passed
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

3 participants