Skip to content

Commit bf226cf

Browse files
committed
Update capture-stdout-stderr.rst
1 parent 202d908 commit bf226cf

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

doc/en/how-to/capture-stdout-stderr.rst

+15-26
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ of the failing function and hide the other one:
106106
Accessing captured output from a test function
107107
---------------------------------------------------
108108

109-
The ``capsys``, ``capsysbinary``, ``capfd``, and ``capfdbinary`` fixtures
110-
allow access to stdout/stderr output created during test execution. Here is
111-
an example test function that performs some output related checks:
109+
The :fixture:`capsys`, :fixture:`capsysbinary`, :fixture:`capfd`, and :fixture:`capfdbinary` fixtures
110+
allow access to ``stdout``/``stderr`` output created during test execution.
111+
112+
Here is an example test function that performs some output related checks:
112113

113114
.. code-block:: python
114115
@@ -125,39 +126,27 @@ an example test function that performs some output related checks:
125126
The ``readouterr()`` call snapshots the output so far -
126127
and capturing will be continued. After the test
127128
function finishes the original streams will
128-
be restored. Using ``capsys`` this way frees your
129+
be restored. Using :fixture:`capsys` this way frees your
129130
test from having to care about setting/resetting
130131
output streams and also interacts well with pytest's
131132
own per-test capturing.
132133

133-
If you want to capture on filedescriptor level you can use
134-
the ``capfd`` fixture which offers the exact
135-
same interface but allows to also capture output from
136-
libraries or subprocesses that directly write to operating
137-
system level output streams (FD1 and FD2).
138-
139-
140-
141134
The return value from ``readouterr`` changed to a ``namedtuple`` with two attributes, ``out`` and ``err``.
142135

143-
144-
145-
If the code under test writes non-textual data, you can capture this using
146-
the ``capsysbinary`` fixture which instead returns ``bytes`` from
136+
If the code under test writes non-textual data (``bytes``), you can capture this using
137+
the :fixture:`capsysbinary` fixture which instead returns ``bytes`` from
147138
the ``readouterr`` method.
148139

140+
If you want to capture at the file descriptor level you can use
141+
the :fixture:`capfd` fixture which offers the exact
142+
same interface but allows to also capture output from
143+
libraries or subprocesses that directly write to operating
144+
system level output streams (FD1 and FD2). Similarly to :fixture:`capsysbinary`, :fixture:`capfdbinary` can be
145+
used to capture ``bytes`` at the file descriptor level.
149146

150147

151-
152-
If the code under test writes non-textual data on a filedescriptor level, you
153-
can capture this using the ``capfdbinary`` fixture which instead returns
154-
``bytes`` from the ``readouterr`` method.
155-
156-
157-
158-
159-
To temporarily disable capture within a test, both ``capsys``
160-
and ``capfd`` have a ``disabled()`` method that can be used
148+
To temporarily disable capture within a test, both :fixture:`capsys`
149+
and :fixture:`capfd` have a ``disabled()`` method that can be used
161150
as a context manager, disabling capture inside the ``with`` block:
162151

163152
.. code-block:: python

0 commit comments

Comments
 (0)