Skip to content

Commit

Permalink
deprecated_call detects pending warnings again
Browse files Browse the repository at this point in the history
`deprecated_call` now looks for PendingDeprecationWarnings,
as it did previously but was broken by pytest-dev#897. Fixes pytest-dev#1037.

Also added a test so this does not happen again.
  • Loading branch information
hunse committed Sep 28, 2015
1 parent 22e1f49 commit e8261e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion _pytest/recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def deprecated_call(func, *args, **kwargs):
warnings.simplefilter('always') # ensure all warnings are triggered
ret = func(*args, **kwargs)

if not any(r.category is DeprecationWarning for r in wrec):
depwarnings = (DeprecationWarning, PendingDeprecationWarning)
if not any(r.category in depwarnings for r in wrec):
__tracebackhide__ = True
raise AssertionError("%r did not produce DeprecationWarning" % (func,))

Expand Down
9 changes: 6 additions & 3 deletions testing/test_recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def dep_explicit(i):
class TestDeprecatedCall(object):
def test_deprecated_call_raises(self):
excinfo = pytest.raises(AssertionError,
"pytest.deprecated_call(dep, 3)")
"pytest.deprecated_call(dep, 3)")
assert str(excinfo).find("did not produce") != -1

def test_deprecated_call(self):
Expand All @@ -105,12 +105,16 @@ def test_deprecated_call_preserves(self):

def test_deprecated_explicit_call_raises(self):
pytest.raises(AssertionError,
"pytest.deprecated_call(dep_explicit, 3)")
"pytest.deprecated_call(dep_explicit, 3)")

def test_deprecated_explicit_call(self):
pytest.deprecated_call(dep_explicit, 0)
pytest.deprecated_call(dep_explicit, 0)

def test_deprecated_call_pending(self):
f = lambda: py.std.warnings.warn(PendingDeprecationWarning("hi"))
pytest.deprecated_call(f)


class TestWarns(object):
def test_strings(self):
Expand Down Expand Up @@ -181,4 +185,3 @@ def test(run):
''')
result = testdir.runpytest()
result.stdout.fnmatch_lines(['*2 passed in*'])

0 comments on commit e8261e0

Please sign in to comment.