Skip to content

Commit 71baf24

Browse files
dalvizuhugovknicoddemus
authored
Doc update: clarify -W syntax (pytest-dev#9464)
Co-authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent fa43b8d commit 71baf24

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

doc/en/how-to/capture-warnings.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ Running pytest now produces this output:
4242
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
4343
======================= 1 passed, 1 warning in 0.12s =======================
4444
45-
The ``-W`` flag can be passed to control which warnings will be displayed or even turn
46-
them into errors:
45+
Controlling warnings
46+
--------------------
47+
48+
Similar to Python's `warning filter`_ and :option:`-W option <python:-W>` flag, pytest provides
49+
its own ``-W`` flag to control which warnings are ignored, displayed, or turned into
50+
errors. See the `warning filter`_ documentation for more
51+
advanced use-cases.
52+
53+
.. _`warning filter`: https://docs.python.org/3/library/warnings.html#warning-filter
54+
55+
This code sample shows how to treat any ``UserWarning`` category class of warning
56+
as an error:
4757

4858
.. code-block:: pytest
4959
@@ -96,9 +106,6 @@ all other warnings into errors.
96106
When a warning matches more than one option in the list, the action for the last matching option
97107
is performed.
98108

99-
Both ``-W`` command-line option and ``filterwarnings`` ini option are based on Python's own
100-
:option:`-W option <python:-W>` and :func:`warnings.simplefilter`, so please refer to those sections in the Python
101-
documentation for other examples and advanced usage.
102109

103110
.. _`filterwarnings`:
104111

0 commit comments

Comments
 (0)