Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and

## Unreleased

- [#970](https://github.com/pytask-dev/pytask/pull/970) prevents tee-sys capture from
replaying output that was already displayed when capture stops before its buffer is
read.
- [#968](https://github.com/pytask-dev/pytask/pull/968) improves the performance of file
descriptor capture for tasks that produce no output.
- Documents the pytest provenance of the adapted debugging, marker, and warning
Expand Down
6 changes: 5 additions & 1 deletion src/_pytask/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,11 @@ def start_capturing(self) -> None:

def stop_capturing(self) -> None:
if self._capturing is not None:
self._capturing.pop_outerr_to_orig()
if self._method == CaptureMethod.TEE_SYS:
# TeeCaptureIO already forwarded the output to the original streams.
self._capturing.readouterr()
else:
self._capturing.pop_outerr_to_orig()
self._capturing.stop_capturing()
self._capturing = None

Expand Down
22 changes: 22 additions & 0 deletions tests/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ def TeeStdCapture( # noqa: N802


class TestCaptureManager:
def test_stop_capturing_does_not_replay_tee_output(self, capsys):
capman = CaptureManager(CaptureMethod.TEE_SYS)
capman.start_capturing()
print("stdout")
print("stderr", file=sys.stderr)

capman.stop_capturing()

captured = capsys.readouterr()
assert captured == ("stdout\n", "stderr\n")

def test_stop_capturing_replays_non_tee_output(self, capsys):
capman = CaptureManager(CaptureMethod.SYS)
capman.start_capturing()
print("stdout")
print("stderr", file=sys.stderr)

capman.stop_capturing()

captured = capsys.readouterr()
assert captured == ("stdout\n", "stderr\n")

@pytest.mark.parametrize(
"method", [CaptureMethod.NO, CaptureMethod.SYS, CaptureMethod.FD]
)
Expand Down