Skip to content

Commit 20bb9b9

Browse files
committed
Tweak docs on review
1 parent 83535ce commit 20bb9b9

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

changelog/9288.breaking.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
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.

src/_pytest/recwarn.py

+4-8
Original file line numberDiff line numberDiff 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__,

0 commit comments

Comments
 (0)