Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ Henk-Jaap Wagenaar
Henry Schreiner
Holger Kohr
Hugo van Kemenade
Hugohong258
Hui Wang (coldnight)
Ian Bicking
Ian Lesperance
Expand Down
10 changes: 10 additions & 0 deletions doc/en/how-to/capture-stdout-stderr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ Here is an example test function that performs some output related checks:

.. code-block:: python

# content of test_output.py
import sys


def test_myoutput(capsys): # or use "capfd" for fd-level
print("hello")
sys.stderr.write("world\n")
Expand All @@ -131,6 +135,12 @@ Here is an example test function that performs some output related checks:
captured = capsys.readouterr()
assert captured.out == "next\n"

.. code-block:: pytest

$ pytest -q test_output.py
. [100%]
1 passed in 0.12s

The ``readouterr()`` call snapshots the output so far -
and capturing will be continued. After the test
function finishes the original streams will
Expand Down