Skip to content

Commit 839909f

Browse files
committed
Merge pull request #1081 from hunse/fix-pendingdep
`deprecated_call` detects pending warnings again
2 parents 22e1f49 + 4194c9c commit 839909f

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
2.8.1.dev
22
---------
33

4+
- 'deprecated_call' is now only satisfied with a DeprecationWarning or
5+
PendingDeprecationWarning. Before 2.8.0, it accepted any warning, and 2.8.0
6+
made it accept only DeprecationWarning (but not PendingDeprecationWarning).
7+
Thanks Alex Gaynor for the issue and Eric Hunsberger for the PR.
8+
49
- fix issue #1073: avoid calling __getattr__ on potential plugin objects.
510
This fixes an incompatibility with pytest-django. Thanks Andreas Pelme,
611
Bruno Oliveira and Ronny Pfannschmidt for contributing and Holger Krekel

_pytest/recwarn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def deprecated_call(func, *args, **kwargs):
3636
warnings.simplefilter('always') # ensure all warnings are triggered
3737
ret = func(*args, **kwargs)
3838

39-
if not any(r.category is DeprecationWarning for r in wrec):
39+
depwarnings = (DeprecationWarning, PendingDeprecationWarning)
40+
if not any(r.category in depwarnings for r in wrec):
4041
__tracebackhide__ = True
4142
raise AssertionError("%r did not produce DeprecationWarning" % (func,))
4243

testing/test_recwarn.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def dep_explicit(i):
8181
class TestDeprecatedCall(object):
8282
def test_deprecated_call_raises(self):
8383
excinfo = pytest.raises(AssertionError,
84-
"pytest.deprecated_call(dep, 3)")
84+
"pytest.deprecated_call(dep, 3)")
8585
assert str(excinfo).find("did not produce") != -1
8686

8787
def test_deprecated_call(self):
@@ -105,12 +105,24 @@ def test_deprecated_call_preserves(self):
105105

106106
def test_deprecated_explicit_call_raises(self):
107107
pytest.raises(AssertionError,
108-
"pytest.deprecated_call(dep_explicit, 3)")
108+
"pytest.deprecated_call(dep_explicit, 3)")
109109

110110
def test_deprecated_explicit_call(self):
111111
pytest.deprecated_call(dep_explicit, 0)
112112
pytest.deprecated_call(dep_explicit, 0)
113113

114+
def test_deprecated_call_pending(self):
115+
f = lambda: py.std.warnings.warn(PendingDeprecationWarning("hi"))
116+
pytest.deprecated_call(f)
117+
118+
def test_deprecated_call_specificity(self):
119+
other_warnings = [Warning, UserWarning, SyntaxWarning, RuntimeWarning,
120+
FutureWarning, ImportWarning, UnicodeWarning]
121+
for warning in other_warnings:
122+
f = lambda: py.std.warnings.warn(warning("hi"))
123+
with pytest.raises(AssertionError):
124+
pytest.deprecated_call(f)
125+
114126

115127
class TestWarns(object):
116128
def test_strings(self):
@@ -181,4 +193,3 @@ def test(run):
181193
''')
182194
result = testdir.runpytest()
183195
result.stdout.fnmatch_lines(['*2 passed in*'])
184-

0 commit comments

Comments
 (0)