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

Function capsys

src/_pytest/capture.py:1007–1031  ·  src/_pytest/capture.py::capsys

r"""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. Returns an instance of :class:`CaptureFi

(request: SubRequest)

Source from the content-addressed store, hash-verified

1005
1006@fixture
1007def capsys(request: SubRequest) -> Generator[CaptureFixture[str]]:
1008 rclass="st">"""Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.
1009
1010 The captured output is made available via ``capsys.readouterr()`` method
1011 calls, which return a ``(out, err)`` namedtuple.
1012 ``out`` and ``err`` will be ``text`` objects.
1013
1014 Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.
1015
1016 Example:
1017
1018 .. code-block:: python
1019
1020 def test_output(capsys):
1021 print(class="st">"hello")
1022 captured = capsys.readouterr()
1023 assert captured.out == class="st">"hello\n"
1024 class="st">"""
1025 capman: CaptureManager = request.config.pluginmanager.getplugin(class="st">"capturemanager")
1026 capture_fixture = CaptureFixture(SysCapture, request, _ispytest=True)
1027 capman.set_fixture(capture_fixture)
1028 capture_fixture._start()
1029 yield capture_fixture
1030 capture_fixture.close()
1031 capman.unset_fixture()
1032
1033
1034@fixture

Callers

nothing calls this directly

Calls 6

_startMethod · 0.95
closeMethod · 0.95
CaptureFixtureClass · 0.85
getpluginMethod · 0.80
set_fixtureMethod · 0.80
unset_fixtureMethod · 0.80

Tested by

no test coverage detected