Skip to content

deprecated_call detects pending warnings again #1081

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 2 commits into from
Sep 28, 2015
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
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
2.8.1.dev
---------

- 'deprecated_call' is now only satisfied with a DeprecationWarning or
PendingDeprecationWarning. Before 2.8.0, it accepted any warning, and 2.8.0
made it accept only DeprecationWarning (but not PendingDeprecationWarning).
Thanks Alex Gaynor for the issue and Eric Hunsberger for the PR.

- fix issue #1073: avoid calling __getattr__ on potential plugin objects.
This fixes an incompatibility with pytest-django. Thanks Andreas Pelme,
Bruno Oliveira and Ronny Pfannschmidt for contributing and Holger Krekel
Expand Down
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
17 changes: 14 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,24 @@ 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)

def test_deprecated_call_specificity(self):
other_warnings = [Warning, UserWarning, SyntaxWarning, RuntimeWarning,
FutureWarning, ImportWarning, UnicodeWarning]
for warning in other_warnings:
f = lambda: py.std.warnings.warn(warning("hi"))
with pytest.raises(AssertionError):
pytest.deprecated_call(f)


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