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

Function capfd

src/_pytest/capture.py:1098–1122  ·  view source on GitHub ↗

r"""Enable text capturing of writes to file descriptors ``1`` and ``2``. The captured output is made available via ``capfd.readouterr()`` method calls, which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``text`` objects. Returns an instance of :class:`CaptureFixt

(request: SubRequest)

Source from the content-addressed store, hash-verified

1096
1097@fixture
1098def capfd(request: SubRequest) -> Generator[CaptureFixture[str]]:
1099 r"""Enable text capturing of writes to file descriptors ``1`` and ``2``.
1100
1101 The captured output is made available via ``capfd.readouterr()`` method
1102 calls, which return a ``(out, err)`` namedtuple.
1103 ``out`` and ``err`` will be ``text`` objects.
1104
1105 Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.
1106
1107 Example:
1108
1109 .. code-block:: python
1110
1111 def test_system_echo(capfd):
1112 os.system('echo "hello"')
1113 captured = capfd.readouterr()
1114 assert captured.out == "hello\n"
1115 """
1116 capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager")
1117 capture_fixture = CaptureFixture(FDCapture, request, _ispytest=True)
1118 capman.set_fixture(capture_fixture)
1119 capture_fixture._start()
1120 yield capture_fixture
1121 capture_fixture.close()
1122 capman.unset_fixture()
1123
1124
1125@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