@@ -128,7 +128,7 @@ is performed.
128128
129129
130130
131- You can use the `` @pytest.mark.filterwarnings `` to add warning filters to specific test items,
131+ You can use the :ref: ` @pytest.mark.filterwarnings < pytest.mark.filterwarnings ref >` mark to add warning filters to specific test items,
132132allowing you to have finer control of which warnings should be captured at test, class or
133133even module level:
134134
@@ -147,10 +147,30 @@ even module level:
147147 assert api_v1() == 1
148148
149149
150+ You can specify multiple filters with separate decorators:
151+
152+ .. code-block :: python
153+
154+ # Ignore "api v1" warnings, but fail on all other warnings
155+ @pytest.mark.filterwarnings (" ignore:api v1" )
156+ @pytest.mark.filterwarnings (" error" )
157+ def test_one ():
158+ assert api_v1() == 1
159+
160+ .. important ::
161+
162+ Regarding decorator order and filter precedence:
163+ it's important to remember that decorators are evaluated in reverse order,
164+ so you have to list the warning filters in the reverse order
165+ compared to traditional :py:func: `warnings.filterwarnings ` and :option: `-W option <python:-W> ` usage.
166+ This means in practice that filters from earlier :ref: `@pytest.mark.filterwarnings <pytest.mark.filterwarnings ref >` decorators
167+ take precedence over filters from later decorators, as illustrated in the example above.
168+
169+
150170Filters applied using a mark take precedence over filters passed on the command line or configured
151- by the `` filterwarnings ` ` ini option.
171+ by the :confval: ` filterwarnings ` ini option.
152172
153- You may apply a filter to all tests of a class by using the `` filterwarnings ` ` mark as a class
173+ You may apply a filter to all tests of a class by using the :ref: ` filterwarnings < pytest.mark.filterwarnings ref > ` mark as a class
154174decorator or to all tests in a module by setting the :globalvar: `pytestmark ` variable:
155175
156176.. code-block :: python
@@ -159,6 +179,13 @@ decorator or to all tests in a module by setting the :globalvar:`pytestmark` var
159179 pytestmark = pytest.mark.filterwarnings(" error" )
160180
161181
182+ .. note ::
183+
184+ If you want to apply multiple filters
185+ (by assigning a list of :ref: `filterwarnings <pytest.mark.filterwarnings ref >` mark to :globalvar: `pytestmark `),
186+ you must use the traditional :py:func: `warnings.filterwarnings ` ordering approach (later filters take precedence),
187+ which is the reverse of the decorator approach mentioned above.
188+
162189
163190*Credits go to Florian Schulze for the reference implementation in the * `pytest-warnings `_
164191*plugin. *
0 commit comments