File tree 2 files changed +11
-9
lines changed
2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 1
- Set :func: `warns ` to re-emit unmatched warnings when the context closes
1
+ :func: `pytest.warns <warns> ` now re-emits unmatched warnings when the context
2
+ closes -- previously it would consume all warnings, hiding those that were not
3
+ matched by the function.
4
+
5
+ While this is a new feature, we decided to announce this as a breaking change
6
+ because many test suites are configured to error-out on warnings, and will
7
+ therefore fail on the newly-re-emitted warnings.
Original file line number Diff line number Diff line change @@ -117,10 +117,10 @@ def warns( # noqa: F811
117
117
warning of that class or classes.
118
118
119
119
This helper produces a list of :class:`warnings.WarningMessage` objects, one for
120
- each warning raised (regardless of whether it is an ``expected_warning`` or not).
120
+ each warning emitted (regardless of whether it is an ``expected_warning`` or not).
121
+ Since pytest 8.0, unmatched warnings are also re-emitted when the context closes.
121
122
122
- This function can be used as a context manager, which will capture all the raised
123
- warnings inside it::
123
+ This function can be used as a context manager::
124
124
125
125
>>> import pytest
126
126
>>> with pytest.warns(RuntimeWarning):
@@ -150,10 +150,6 @@ def warns( # noqa: F811
150
150
This could be achieved in the same way as with exceptions, see
151
151
:ref:`parametrizing_conditional_raising` for an example.
152
152
153
- .. note::
154
- Unlike the stdlib :func:`warnings.catch_warnings` context manager,
155
- unmatched warnings will be re-emitted when the context closes.
156
-
157
153
"""
158
154
__tracebackhide__ = True
159
155
if not args :
@@ -328,7 +324,7 @@ def found_str():
328
324
if not self .matches (w ):
329
325
warnings .warn_explicit (
330
326
str (w .message ),
331
- w .message .__class__ , # type: ignore
327
+ w .message .__class__ , # type: ignore[arg-type]
332
328
w .filename ,
333
329
w .lineno ,
334
330
module = w .__module__ ,
You can’t perform that action at this time.
0 commit comments