Skip to content

Commit

Permalink
Tweak docs on review
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jun 30, 2023
1 parent 7022fb4 commit 2d48171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 7 additions & 1 deletion changelog/9288.breaking.rst
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
Set :func:`warns` to re-emit unmatched warnings when the context closes
:func:`pytest.warns <warns>` now re-emits unmatched warnings when the context
closes -- previously it would consume all warnings, hiding those that were not
matched by the function.

While this is a new feature, we decided to announce this as a breaking change
because many test suites are configured to error-out on warnings, and will
therefore fail on the newly-re-emitted warnings.
12 changes: 4 additions & 8 deletions src/_pytest/recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def warns( # noqa: F811
warning of that class or classes.
This helper produces a list of :class:`warnings.WarningMessage` objects, one for
each warning raised (regardless of whether it is an ``expected_warning`` or not).
each warning emitted (regardless of whether it is an ``expected_warning`` or not).
Since pytest 8.0, unmatched warnings are also re-emitted when the context closes.
This function can be used as a context manager, which will capture all the raised
warnings inside it::
This function can be used as a context manager::
>>> import pytest
>>> with pytest.warns(RuntimeWarning):
Expand Down Expand Up @@ -150,10 +150,6 @@ def warns( # noqa: F811
This could be achieved in the same way as with exceptions, see
:ref:`parametrizing_conditional_raising` for an example.
.. note::
Unlike the stdlib :func:`warnings.catch_warnings` context manager,
unmatched warnings will be re-emitted when the context closes.
"""
__tracebackhide__ = True
if not args:
Expand Down Expand Up @@ -328,7 +324,7 @@ def found_str():
if not self.matches(w):
warnings.warn_explicit(
str(w.message),
w.message.__class__, # type: ignore
w.message.__class__, # type: ignore[arg-type]
w.filename,
w.lineno,
module=w.__module__,
Expand Down

0 comments on commit 2d48171

Please sign in to comment.