File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 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
117117 warning of that class or classes.
118118
119119 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.
121122
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::
124124
125125 >>> import pytest
126126 >>> with pytest.warns(RuntimeWarning):
@@ -150,10 +150,6 @@ def warns( # noqa: F811
150150 This could be achieved in the same way as with exceptions, see
151151 :ref:`parametrizing_conditional_raising` for an example.
152152
153- .. note::
154- Unlike the stdlib :func:`warnings.catch_warnings` context manager,
155- unmatched warnings will be re-emitted when the context closes.
156-
157153 """
158154 __tracebackhide__ = True
159155 if not args :
@@ -328,7 +324,7 @@ def found_str():
328324 if not self .matches (w ):
329325 warnings .warn_explicit (
330326 str (w .message ),
331- w .message .__class__ , # type: ignore
327+ w .message .__class__ , # type: ignore[arg-type]
332328 w .filename ,
333329 w .lineno ,
334330 module = w .__module__ ,
You can’t perform that action at this time.
0 commit comments