From 8062743f6b03f43d2c06d4c6a4b4b0a9bf91b5ea Mon Sep 17 00:00:00 2001 From: Chris Mahoney <44449504+chrimaho@users.noreply.github.com> Date: Mon, 18 Sep 2023 22:34:05 +1000 Subject: [PATCH] Change deprecated_call to handle FutureWarning (#11448) Fixes #11447 --- changelog/11447.improvement.rst | 1 + src/_pytest/recwarn.py | 6 ++++-- testing/test_recwarn.py | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelog/11447.improvement.rst diff --git a/changelog/11447.improvement.rst b/changelog/11447.improvement.rst new file mode 100644 index 00000000000..96be8dffe60 --- /dev/null +++ b/changelog/11447.improvement.rst @@ -0,0 +1 @@ +:func:`pytest.deprecated_call` now also considers warnings of type :class:`FutureWarning`. diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 5484d6f3b33..d1d83ea2a13 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -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:: @@ -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 diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index 8b70c8afffa..19a1cd534f1 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -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]) @@ -221,7 +221,6 @@ def test_deprecated_call_specificity(self) -> None: UserWarning, SyntaxWarning, RuntimeWarning, - FutureWarning, ImportWarning, UnicodeWarning, ]