From a6ced30635af1f1c33b23c45d7e271b89a6c55cb Mon Sep 17 00:00:00 2001 From: Michael_Interface Date: Sat, 20 Dec 2025 19:50:05 +0300 Subject: [PATCH 1/4] doc: add note about capture fixture use --- doc/en/how-to/capture-stdout-stderr.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/en/how-to/capture-stdout-stderr.rst b/doc/en/how-to/capture-stdout-stderr.rst index 14807b9b777..9d54836f480 100644 --- a/doc/en/how-to/capture-stdout-stderr.rst +++ b/doc/en/how-to/capture-stdout-stderr.rst @@ -129,6 +129,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. + The ``readouterr()`` call snapshots the output so far - and capturing will be continued. After the test function finishes the original streams will From 1adc317fc853d75d773753be9844de3eee55f417 Mon Sep 17 00:00:00 2001 From: Michael_Interface Date: Sat, 20 Dec 2025 20:11:44 +0300 Subject: [PATCH 2/4] doc: new label; changelog --- changelog/13731.doc.rst | 1 + doc/en/how-to/capture-stdout-stderr.rst | 2 ++ 2 files changed, 3 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 9d54836f480..a80891b2ffd 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 --------------------------------------------------- From fb6e624112c2f1e57b5c0536fd5cff6df6e0655f Mon Sep 17 00:00:00 2001 From: Michael_Interface Date: Sun, 28 Dec 2025 21:13:35 +0300 Subject: [PATCH 3/4] doc: move the note --- doc/en/how-to/capture-stdout-stderr.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/doc/en/how-to/capture-stdout-stderr.rst b/doc/en/how-to/capture-stdout-stderr.rst index a80891b2ffd..11181bfa6fc 100644 --- a/doc/en/how-to/capture-stdout-stderr.rst +++ b/doc/en/how-to/capture-stdout-stderr.rst @@ -132,15 +132,6 @@ Here is an example test function that performs some output related checks: 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. The ``readouterr()`` call snapshots the output so far - and capturing will be continued. After the test @@ -175,3 +166,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. From bb28508e3744be7e400a0eada5825e2eea600bb4 Mon Sep 17 00:00:00 2001 From: Michael_Interface Date: Sun, 28 Dec 2025 21:15:05 +0300 Subject: [PATCH 4/4] doc: restore doc --- doc/en/how-to/capture-stdout-stderr.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/en/how-to/capture-stdout-stderr.rst b/doc/en/how-to/capture-stdout-stderr.rst index 11181bfa6fc..8a6a42d4134 100644 --- a/doc/en/how-to/capture-stdout-stderr.rst +++ b/doc/en/how-to/capture-stdout-stderr.rst @@ -131,8 +131,6 @@ Here is an example test function that performs some output related checks: captured = capsys.readouterr() assert captured.out == "next\n" - - The ``readouterr()`` call snapshots the output so far - and capturing will be continued. After the test function finishes the original streams will