Merge pull request #2446 from nicoddemus/issue-2441
pytest.deprecated_call now captures PendingDeprecationWarning in context manager form
This commit is contained in:
commit
454426cba5
|
@ -45,7 +45,7 @@ def deprecated_call(func=None, *args, **kwargs):
|
||||||
triggered twice for the same module. See #1190.
|
triggered twice for the same module. See #1190.
|
||||||
"""
|
"""
|
||||||
if not func:
|
if not func:
|
||||||
return WarningsChecker(expected_warning=DeprecationWarning)
|
return WarningsChecker(expected_warning=(DeprecationWarning, PendingDeprecationWarning))
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
``pytest.deprecated_call`` now captures ``PendingDeprecationWarning`` in context manager form.
|
|
@ -109,14 +109,17 @@ class TestDeprecatedCall(object):
|
||||||
with pytest.deprecated_call():
|
with pytest.deprecated_call():
|
||||||
self.dep(1)
|
self.dep(1)
|
||||||
|
|
||||||
def test_deprecated_call_as_context_manager(self):
|
@pytest.mark.parametrize('warning_type', [PendingDeprecationWarning, DeprecationWarning])
|
||||||
with pytest.deprecated_call():
|
@pytest.mark.parametrize('mode', ['context_manager', 'call'])
|
||||||
self.dep(0)
|
def test_deprecated_call_modes(self, warning_type, mode):
|
||||||
|
|
||||||
def test_deprecated_call_pending(self):
|
|
||||||
def f():
|
def f():
|
||||||
py.std.warnings.warn(PendingDeprecationWarning("hi"))
|
warnings.warn(warning_type("hi"))
|
||||||
pytest.deprecated_call(f)
|
|
||||||
|
if mode == 'call':
|
||||||
|
pytest.deprecated_call(f)
|
||||||
|
else:
|
||||||
|
with pytest.deprecated_call():
|
||||||
|
f()
|
||||||
|
|
||||||
def test_deprecated_call_specificity(self):
|
def test_deprecated_call_specificity(self):
|
||||||
other_warnings = [Warning, UserWarning, SyntaxWarning, RuntimeWarning,
|
other_warnings = [Warning, UserWarning, SyntaxWarning, RuntimeWarning,
|
||||||
|
|
Loading…
Reference in New Issue