Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,14 +1049,20 @@ def test_output(capteesys):
assert captured.out == "hello\n"
"""
capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager")
capture_fixture = CaptureFixture(
SysCapture, request, config=dict(tee=True), _ispytest=True
)
capman.set_fixture(capture_fixture)
capture_fixture._start()
yield capture_fixture
capture_fixture.close()
capman.unset_fixture()
if capman.is_globally_capturing():
capture_fixture = CaptureFixture(
SysCapture, request, config=dict(tee=True), _ispytest=True
)
capman.set_fixture(capture_fixture)
capture_fixture._start()
yield capture_fixture
capture_fixture.close()
capman.unset_fixture()
else:
# capteesys does nothing when global capturing is disabled.
# This is so that the "tee" part of cap-tee-sys is not
# implemented without the "cap" part.
yield CaptureFixture(SysCapture, request, _ispytest=True)


@fixture
Expand Down
16 changes: 16 additions & 0 deletions testing/test_capteesys_issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
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.

request: SubRequest, capteesys: CaptureFixture[str]
) -> None:
print("Hello world stdout", flush=True)
print("Hello world stderr", file=sys.stderr, flush=True)