Skip to content

Commit 8f5b07d

Browse files
Docs: clarify capture fixture precedence over -s (#14053)
Clarify in the capturing tutorial that using capture fixtures such as capsys or capfd re-enables capturing for the duration of the test, even when global capturing is disabled via `-s` or `--capture=no`. Closes #13731
1 parent 0bd0e9b commit 8f5b07d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

changelog/13731.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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>`.

doc/en/how-to/capture-stdout-stderr.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ of the failing function and hide the other one:
109109
FAILED test_module.py::test_func2 - assert False
110110
======================= 1 failed, 1 passed in 0.12s ========================
111111
112+
.. _accessing-captured-output:
113+
112114
Accessing captured output from a test function
113115
---------------------------------------------------
114116

@@ -162,3 +164,13 @@ as a context manager, disabling capture inside the ``with`` block:
162164
with capsys.disabled():
163165
print("output not captured, going directly to sys.stdout")
164166
print("this output is also captured")
167+
168+
.. note::
169+
170+
When a capture fixture such as :fixture:`capsys` or :fixture:`capfd` is used,
171+
it takes precedence over the global capturing configuration set via
172+
command-line options such as ``-s`` or ``--capture=no``.
173+
174+
This means that output produced within a test using a capture fixture will
175+
still be captured and available via ``readouterr()``, even if global capturing
176+
is disabled.

0 commit comments

Comments
 (0)