diff --git a/AUTHORS b/AUTHORS index daa6a471eb9..1ddfff20926 100644 --- a/AUTHORS +++ b/AUTHORS @@ -211,6 +211,7 @@ Henk-Jaap Wagenaar Henry Schreiner Holger Kohr Hugo van Kemenade +Hugohong258 Hui Wang (coldnight) Ian Bicking Ian Lesperance diff --git a/doc/en/how-to/capture-stdout-stderr.rst b/doc/en/how-to/capture-stdout-stderr.rst index 5de89bc0e3f..8b6198176fd 100644 --- a/doc/en/how-to/capture-stdout-stderr.rst +++ b/doc/en/how-to/capture-stdout-stderr.rst @@ -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") @@ -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