Skip to content

Commit fc4f769

Browse files
Merge pull request #3336 from nicoddemus/filter-warnings-ref-doc
Add missing reference doc for filterwarnings mark
2 parents 672239b + f78953f commit fc4f769

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

doc/en/reference.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,31 @@ Marks can be used apply meta data to *test functions* (but not fixtures), which
9494
fixtures or plugins.
9595

9696

97+
.. _`pytest.mark.filterwarnings ref`:
98+
99+
pytest.mark.filterwarnings
100+
~~~~~~~~~~~~~~~~~~~~~~~~~~
101+
102+
**Tutorial**: :ref:`filterwarnings`.
103+
104+
Add warning filters to marked test items.
105+
106+
.. py:function:: pytest.mark.filterwarnings(filter)
107+
108+
:keyword str filter:
109+
A *warning specification string*, which is composed of contents of the tuple ``(action, message, category, module, lineno)``
110+
as specified in `The Warnings filter <https://docs.python.org/3/library/warnings.html#warning-filter>`_ section of
111+
the Python documentation, separated by ``":"``. Optional fields can be omitted.
112+
113+
For example:
114+
115+
.. code-block:: python
116+
117+
@pytest.mark.warnings("ignore:.*usage will be deprecated.*:DeprecationWarning")
118+
def test_foo():
119+
...
120+
121+
97122
.. _`pytest.mark.parametrize ref`:
98123

99124
pytest.mark.parametrize
@@ -991,7 +1016,7 @@ passed multiple times. The expected format is ``name=value``. For example::
9911016
.. code-block:: ini
9921017
9931018
[pytest]
994-
log_cli_level = INFO
1019+
log_cli_level = INFO
9951020
9961021
For more information, see :ref:`live_logs`.
9971022

doc/en/warnings.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ Running pytest now produces this output::
2525
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
2626
rootdir: $REGENDOC_TMPDIR, inifile:
2727
collected 1 item
28-
28+
2929
test_show_warnings.py . [100%]
30-
30+
3131
============================= warnings summary =============================
3232
test_show_warnings.py::test_one
3333
$REGENDOC_TMPDIR/test_show_warnings.py:4: UserWarning: api v1, should use functions from v2
3434
warnings.warn(UserWarning("api v1, should use functions from v2"))
35-
35+
3636
-- Docs: http://doc.pytest.org/en/latest/warnings.html
3737
=================== 1 passed, 1 warnings in 0.12 seconds ===================
3838

@@ -45,17 +45,17 @@ them into errors::
4545
F [100%]
4646
================================= FAILURES =================================
4747
_________________________________ test_one _________________________________
48-
48+
4949
def test_one():
5050
> assert api_v1() == 1
51-
52-
test_show_warnings.py:8:
53-
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
54-
51+
52+
test_show_warnings.py:8:
53+
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
54+
5555
def api_v1():
5656
> warnings.warn(UserWarning("api v1, should use functions from v2"))
5757
E UserWarning: api v1, should use functions from v2
58-
58+
5959
test_show_warnings.py:4: UserWarning
6060
1 failed in 0.12 seconds
6161

@@ -78,6 +78,9 @@ Both ``-W`` command-line option and ``filterwarnings`` ini option are based on P
7878
`-W option`_ and `warnings.simplefilter`_, so please refer to those sections in the Python
7979
documentation for other examples and advanced usage.
8080

81+
82+
.. _`filterwarnings`:
83+
8184
``@pytest.mark.filterwarnings``
8285
-------------------------------
8386

0 commit comments

Comments
 (0)