Skip to content

Conversation

ron-42
Copy link

@ron-42 ron-42 commented Oct 7, 2025

Summary

Using the capteesys fixture with -s (--capture=no) printed output twice, even if the fixture wasn’t used in the test body. This issue is tracked in [pytest-dev/pytest#13784](#13784) and is fixed by this PR.

Fixes: #13784


Root Cause

capteesys always instantiated a tee-ing SysCapture, so when global capture was disabled (-s), output went directly to the terminal and was also duplicated through the tee path.


Fix

Enable tee only when global capture is active. When global capture is disabled, capteesys yields a non-teeing fixture to avoid duplication.

Changes localized to: src/_pytest/capture.py (capteesys fixture)


Tests

Added regression test: test_capteesys_issue.py

  • Reproduces duplication with -s and validates the fix.

Behavior Comparison

Before:
Running pytest -s with capteesys in the test signature duplicated stdout/stderr.

After:
pytest -s prints each line exactly once (no duplication).
With capture enabled, capteesys continues to tee and capture as expected.


Backwards Compatibility

  • No public API changes.
  • Behavior now aligns with the selected global --capture mode.

Affected Files

  • src/_pytest/capture.py
  • test_capteesys_issue.py

from _pytest.fixtures import SubRequest


def test_dummy_test_with_traceback(
Copy link
Member

Choose a reason for hiding this comment

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

This test doesn't seem to do anything. I suggest looking at other tests in testing/test_capture.py and adding a test there.

Copy link
Author

Choose a reason for hiding this comment

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

Moved the regression test into test_capture.py as requested; added test_capteesys_no_global_capture; removed the standalone test file.

Copy link
Author

@ron-42 ron-42 Oct 10, 2025

Choose a reason for hiding this comment

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

Review the changes and do let me know if further changes required.

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.

2 participants