Skip to content

Commit

Permalink
Change deprecated_call to handle FutureWarning (#11448)
Browse files Browse the repository at this point in the history
Fixes #11447
  • Loading branch information
chrimaho committed Sep 18, 2023
1 parent 8b7f94f commit 8062743
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/11447.improvement.rst
@@ -0,0 +1 @@
:func:`pytest.deprecated_call` now also considers warnings of type :class:`FutureWarning`.
6 changes: 4 additions & 2 deletions src/_pytest/recwarn.py
Expand Up @@ -56,7 +56,7 @@ def deprecated_call( # noqa: F811
def deprecated_call( # noqa: F811
func: Optional[Callable[..., Any]] = None, *args: Any, **kwargs: Any
) -> Union["WarningsRecorder", Any]:
"""Assert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning``.
"""Assert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning`` or ``FutureWarning``.
This function can be used as a context manager::
Expand All @@ -82,7 +82,9 @@ def deprecated_call( # noqa: F811
__tracebackhide__ = True
if func is not None:
args = (func,) + args
return warns((DeprecationWarning, PendingDeprecationWarning), *args, **kwargs)
return warns(
(DeprecationWarning, PendingDeprecationWarning, FutureWarning), *args, **kwargs
)


@overload
Expand Down
3 changes: 1 addition & 2 deletions testing/test_recwarn.py
Expand Up @@ -192,7 +192,7 @@ def f():
f()

@pytest.mark.parametrize(
"warning_type", [PendingDeprecationWarning, DeprecationWarning]
"warning_type", [PendingDeprecationWarning, DeprecationWarning, FutureWarning]
)
@pytest.mark.parametrize("mode", ["context_manager", "call"])
@pytest.mark.parametrize("call_f_first", [True, False])
Expand Down Expand Up @@ -221,7 +221,6 @@ def test_deprecated_call_specificity(self) -> None:
UserWarning,
SyntaxWarning,
RuntimeWarning,
FutureWarning,
ImportWarning,
UnicodeWarning,
]
Expand Down

0 comments on commit 8062743

Please sign in to comment.