Skip to content

pytest.deprecated_call now captures PendingDeprecationWarning in context manager form #2446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _pytest/recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
1 change: 1 addition & 0 deletions changelog/2441.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``pytest.deprecated_call`` now captures ``PendingDeprecationWarning`` in context manager form.
17 changes: 10 additions & 7 deletions testing/test_recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ def test_deprecated_call_as_context_manager_no_warning(self):
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,
Expand Down