Skip to content

Commit

Permalink
Merge pull request #3014 from nicoddemus/cap-named-tuple
Browse files Browse the repository at this point in the history
Change capture docs to use namedtuple
  • Loading branch information
RonnyPfannschmidt authored Dec 9, 2017
2 parents 1c5b887 + 38fb6aa commit 964c29c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions doc/en/capture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ an example test function that performs some output related checks:
.. code-block:: python
def test_myoutput(capsys): # or use "capfd" for fd-level
print ("hello")
print("hello")
sys.stderr.write("world\n")
out, err = capsys.readouterr()
assert out == "hello\n"
assert err == "world\n"
print ("next")
out, err = capsys.readouterr()
assert out == "next\n"
captured = capsys.readouterr()
assert captured.out == "hello\n"
assert captured.err == "world\n"
print("next")
captured = capsys.readouterr()
assert captured.out == "next\n"
The ``readouterr()`` call snapshots the output so far -
and capturing will be continued. After the test
Expand All @@ -117,6 +117,10 @@ system level output streams (FD1 and FD2).

.. versionadded:: 3.3

The return value from ``readouterr`` changed to a ``namedtuple`` with two attributes, ``out`` and ``err``.

.. versionadded:: 3.3

If the code under test writes non-textual data, you can capture this using
the ``capsysbinary`` fixture which instead returns ``bytes`` from
the ``readouterr`` method. The ``capfsysbinary`` fixture is currently only
Expand Down

0 comments on commit 964c29c

Please sign in to comment.