Skip to content

fix: preserve capture fixture output on thread timeouts - #212

Merged
flub merged 3 commits into
pytest-dev:mainfrom
Arham-Begani:fix/fixture-capture-timeout-output
Nov 6, 2026
Merged

flub merged 3 commits into
pytest-dev:mainfrom
Arham-Begani:fix/fixture-capture-timeout-output

Conversation

@Arham-Begani

@Arham-Begani Arham-Begani commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #172.

Thread timeouts can lose output buffered by capsys, capfd, capsysbinary or capfdbinary when the process exits. With --capture=no, fixture capture can also swallow the timeout diagnostics.

This flushes the active capture fixture before reading captured output, then keeps global and fixture capture disabled while reporting the timeout. The existing stack dump and exit code 1 are preserved.

Nine subprocess tests cover the four fixtures with fd capture and --capture=no, plus running without the capture plugin. They use a real timer and process exit. Upstream CI passed all ten Python 3.10–3.14 Linux/Windows jobs at commit 2252ccb.

@Arham-Begani

Copy link
Copy Markdown
Contributor Author

Could a maintainer review the focused thread-timeout capture fix when convenient? At 2252ccb0d3ac8419923040857ef9c46dfddd5ad6, all ten upstream Python 3.10–3.14 Linux/Windows jobs pass.

The change preserves output held by capsys/capfd and their binary variants before the process exits, including --capture=no, while keeping the existing stack dump and exit code. The nine subprocess regressions use the real timer and process exit; eight reproduce the loss before the fix, and the no-capture-plugin control already passes. The scope stays limited to thread-timeout teardown.

No additional code change is proposed here. The implementation, validation and this follow-up used AI assistance, as disclosed in the PR. Thanks for considering the review.

@Arham-Begani

Copy link
Copy Markdown
Contributor Author

Following up on the October 20 review request for 2252ccb0. The upstream Test workflow passes, and the thread-timeout output-capture fix and its subprocess regressions are unchanged.

Could a maintainer review when convenient, or let me know if an adjustment is needed?

This follow-up was prepared with AI assistance.

@flub

flub commented Oct 31, 2026

Copy link
Copy Markdown
Member

If you want to help this issue along please re-write the original into something reasonable human-like. The current description is just way to long and difficult to parse and make sense of.

@Arham-Begani

Copy link
Copy Markdown
Contributor Author

Thanks, @flub. The description is now shortened to the problem, fix and regression coverage. The code is unchanged at 2252ccb, and all ten upstream Linux/Windows test jobs pass.

Could you take another look when convenient?

Prepared with AI assistance.

@flub flub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fixup the changelog. otherwise lgtm

Comment thread README.rst
-----

- Preserve capture-fixture output and disable fixture capturing when reporting
thread timeouts. Thanks Arham Begani.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please start a new section, titled X.Y.Z. Can't add something to a previous version.

Prepared with OpenAI Codex assistance.
Keep the Python 3.15 and capture-fixture notes together under X.Y.Z, as requested in review. Prepared with OpenAI Codex assistance.
@flub
flub merged commit 4babcac into pytest-dev:main Nov 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: Using capturemanager.global_and_fixture_disabled

2 participants