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

Function capfdbinary

src/_pytest/capture.py:1126–1151  ·  view source on GitHub ↗

r"""Enable bytes 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 ``byte`` objects. Returns an instance of :class:`CaptureFix

(request: SubRequest)

Source from the content-addressed store, hash-verified

1124
1125@fixture
1126def capfdbinary(request: SubRequest) -> Generator[CaptureFixture[bytes]]:
1127 r"""Enable bytes capturing of writes to file descriptors ``1`` and ``2``.
1128
1129 The captured output is made available via ``capfd.readouterr()`` method
1130 calls, which return a ``(out, err)`` namedtuple.
1131 ``out`` and ``err`` will be ``byte`` objects.
1132
1133 Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.
1134
1135 Example:
1136
1137 .. code-block:: python
1138
1139 def test_system_echo(capfdbinary):
1140 os.system('echo "hello"')
1141 captured = capfdbinary.readouterr()
1142 assert captured.out == b"hello\n"
1143
1144 """
1145 capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager")
1146 capture_fixture = CaptureFixture(FDCaptureBinary, request, _ispytest=True)
1147 capman.set_fixture(capture_fixture)
1148 capture_fixture._start()
1149 yield capture_fixture
1150 capture_fixture.close()
1151 capman.unset_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