Fix capteesys producing doubled output with --capture=no#14205
Open
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Open
Fix capteesys producing doubled output with --capture=no#14205Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Conversation
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.
for more information, see https://pre-commit.ci
RonnyPfannschmidt
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13784.
Summary
When
capteesysis used with-s(--capture=no), everyprint()call produces doubled output on the terminal.Root cause:
TeeCaptureIO.write()tees output to the original stream in real-time. OnCaptureFixture.close(),pop_outerr_to_orig()callswriteorg()which writes the same buffered content to the original stream a second time.With other capture modes (e.g.
--capture=fd), the "original stream" thatwriteorg()targets is the global capture's pipe — so the double write is absorbed correctly. With--capture=no, there is no global capture, sowriteorg()writes directly to the real terminal, producing the duplicate.Fix: When tee is enabled, use
readouterr()instead ofpop_outerr_to_orig()inclose(), since the output was already delivered live byTeeCaptureIO.Test plan
test_capteesys_no_double_output_with_capture_nothat verifies output appears exactly once when usingcapteesyswith-sTestCaptureFixturetests pass