From f96a1d89c5e8a76708b686c09c16a8017292bf40 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 29 May 2017 22:46:15 -0300 Subject: [PATCH] pytest.deprecated_call now captures PendingDeprecationWarning in context manager form Fix #2441 --- _pytest/recwarn.py | 2 +- changelog/2441.bugfix | 1 + testing/test_recwarn.py | 17 ++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 changelog/2441.bugfix diff --git a/_pytest/recwarn.py b/_pytest/recwarn.py index 7dce842f6..7ad6fef89 100644 --- a/_pytest/recwarn.py +++ b/_pytest/recwarn.py @@ -45,7 +45,7 @@ def deprecated_call(func=None, *args, **kwargs): triggered twice for the same module. See #1190. """ if not func: - return WarningsChecker(expected_warning=DeprecationWarning) + return WarningsChecker(expected_warning=(DeprecationWarning, PendingDeprecationWarning)) categories = [] diff --git a/changelog/2441.bugfix b/changelog/2441.bugfix new file mode 100644 index 000000000..e198d8fa6 --- /dev/null +++ b/changelog/2441.bugfix @@ -0,0 +1 @@ +``pytest.deprecated_call`` now captures ``PendingDeprecationWarning`` in context manager form. diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index 0f921f057..2a379c6ce 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -109,14 +109,17 @@ class TestDeprecatedCall(object): with pytest.deprecated_call(): self.dep(1) - def test_deprecated_call_as_context_manager(self): - with pytest.deprecated_call(): - self.dep(0) - - def test_deprecated_call_pending(self): + @pytest.mark.parametrize('warning_type', [PendingDeprecationWarning, DeprecationWarning]) + @pytest.mark.parametrize('mode', ['context_manager', 'call']) + def test_deprecated_call_modes(self, warning_type, mode): def f(): - py.std.warnings.warn(PendingDeprecationWarning("hi")) - pytest.deprecated_call(f) + warnings.warn(warning_type("hi")) + + if mode == 'call': + pytest.deprecated_call(f) + else: + with pytest.deprecated_call(): + f() def test_deprecated_call_specificity(self): other_warnings = [Warning, UserWarning, SyntaxWarning, RuntimeWarning,