MCPcopy Create free account
hub / github.com/pytest-dev/pytest / capsys

Function capsys

src/_pytest/capture.py:878–891  ·  view source on GitHub ↗

Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``. The captured output is made available via ``capsys.readouterr()`` method calls, which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``text`` objects.

(request: SubRequest)

Source from the content-addressed store, hash-verified

876
877@fixture
878def capsys(request: SubRequest) -> Generator[CaptureFixture[str], None, None]:
879 """Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.
880
881 The captured output is made available via ``capsys.readouterr()`` method
882 calls, which return a ``(out, err)`` namedtuple.
883 ``out`` and ``err`` will be ``text`` objects.
884 """
885 capman = request.config.pluginmanager.getplugin("capturemanager")
886 capture_fixture = CaptureFixture[str](SysCapture, request, _ispytest=True)
887 capman.set_fixture(capture_fixture)
888 capture_fixture._start()
889 yield capture_fixture
890 capture_fixture.close()
891 capman.unset_fixture()
892
893
894@fixture

Callers

nothing calls this directly

Calls 5

getpluginMethod · 0.80
set_fixtureMethod · 0.80
_startMethod · 0.80
unset_fixtureMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected