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 changelog/13731.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarified that capture fixtures (e.g. ``capsys`` and ``capfd``) take precedence over the ``-s`` / ``--capture=no`` command-line options in :ref:`Accessing captured output from a test function <accessing-captured-output>`.
13 changes: 13 additions & 0 deletions doc/en/how-to/capture-stdout-stderr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ of the failing function and hide the other one:
FAILED test_module.py::test_func2 - assert False
======================= 1 failed, 1 passed in 0.12s ========================

.. _accessing-captured-output:

Accessing captured output from a test function
---------------------------------------------------

Expand All @@ -129,6 +131,17 @@ Here is an example test function that performs some output related checks:
captured = capsys.readouterr()
assert captured.out == "next\n"


.. note::

When a capture fixture such as :fixture:`capsys` or :fixture:`capfd` is used,
it takes precedence over the global capturing configuration set via
command-line options such as ``-s`` or ``--capture=no``.

This means that output produced within a test using a capture fixture will
still be captured and available via ``readouterr()``, even if global capturing
is disabled.
Comment on lines +135 to +143
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this note to the bottom of the page. This is a more advanced notice, and as it is now, it gets in the way of the explanation of the basics of the feature.


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