MCPcopy
hub / github.com/pytest-dev/pytest / capturing_output

Function capturing_output

src/_pytest/subtests.py:288–313  ·  view source on GitHub ↗
(request: SubRequest)

Source from the content-addressed store, hash-verified

286
287@contextmanager
288def capturing_output(request: SubRequest) -> Iterator[Captured]:
289 option = request.config.getoption("capture", None)
290
291 capman = request.config.pluginmanager.getplugin("capturemanager")
292 if getattr(capman, "_capture_fixture", None):
293 # capsys or capfd are active, subtest should not capture.
294 fixture = None
295 elif option == "sys":
296 fixture = CaptureFixture(SysCapture, request, _ispytest=True)
297 elif option == "fd":
298 fixture = CaptureFixture(FDCapture, request, _ispytest=True)
299 else:
300 fixture = None
301
302 if fixture is not None:
303 fixture._start()
304
305 captured = Captured()
306 try:
307 yield captured
308 finally:
309 if fixture is not None:
310 out, err = fixture.readouterr()
311 fixture.close()
312 captured.out = out
313 captured.err = err
314
315
316@contextmanager

Callers 1

__enter__Method · 0.85

Calls 7

_startMethod · 0.95
readouterrMethod · 0.95
closeMethod · 0.95
CaptureFixtureClass · 0.90
CapturedClass · 0.85
getoptionMethod · 0.80
getpluginMethod · 0.80

Tested by

no test coverage detected