Skip to content

Commit 38fb6aa

Browse files
committed
Change capture docs to use namedtuple
1 parent 1c5b887 commit 38fb6aa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Diff for: doc/en/capture.rst

+11-7
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ an example test function that performs some output related checks:
9292
.. code-block:: python
9393
9494
def test_myoutput(capsys): # or use "capfd" for fd-level
95-
print ("hello")
95+
print("hello")
9696
sys.stderr.write("world\n")
97-
out, err = capsys.readouterr()
98-
assert out == "hello\n"
99-
assert err == "world\n"
100-
print ("next")
101-
out, err = capsys.readouterr()
102-
assert out == "next\n"
97+
captured = capsys.readouterr()
98+
assert captured.out == "hello\n"
99+
assert captured.err == "world\n"
100+
print("next")
101+
captured = capsys.readouterr()
102+
assert captured.out == "next\n"
103103
104104
The ``readouterr()`` call snapshots the output so far -
105105
and capturing will be continued. After the test
@@ -117,6 +117,10 @@ system level output streams (FD1 and FD2).
117117

118118
.. versionadded:: 3.3
119119

120+
The return value from ``readouterr`` changed to a ``namedtuple`` with two attributes, ``out`` and ``err``.
121+
122+
.. versionadded:: 3.3
123+
120124
If the code under test writes non-textual data, you can capture this using
121125
the ``capsysbinary`` fixture which instead returns ``bytes`` from
122126
the ``readouterr`` method. The ``capfsysbinary`` fixture is currently only

0 commit comments

Comments
 (0)