From dfdbe24b9db30b7ccd227c3e793b271084b31771 Mon Sep 17 00:00:00 2001 From: Bubble-Interface Date: Sun, 28 Dec 2025 22:43:41 +0300 Subject: [PATCH] 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 (cherry picked from commit 8f5b07d87bf803622bb96227ed939f3c95f8809b) --- changelog/13731.doc.rst | 1 + doc/en/how-to/capture-stdout-stderr.rst | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 changelog/13731.doc.rst diff --git a/changelog/13731.doc.rst b/changelog/13731.doc.rst new file mode 100644 index 00000000000..0cfdbebfc40 --- /dev/null +++ b/changelog/13731.doc.rst @@ -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 `. diff --git a/doc/en/how-to/capture-stdout-stderr.rst b/doc/en/how-to/capture-stdout-stderr.rst index 14807b9b777..8a6a42d4134 100644 --- a/doc/en/how-to/capture-stdout-stderr.rst +++ b/doc/en/how-to/capture-stdout-stderr.rst @@ -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 --------------------------------------------------- @@ -162,3 +164,13 @@ as a context manager, disabling capture inside the ``with`` block: with capsys.disabled(): print("output not captured, going directly to sys.stdout") print("this output is also captured") + +.. 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.