Merge pull request #1081 from hunse/fix-pendingdep

`deprecated_call` detects pending warnings again
This commit is contained in:
holger krekel 2015-09-28 19:05:44 +02:00
commit 839909f3f6
3 changed files with 21 additions and 4 deletions

View File

@ -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

View File

@ -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,))

View File

@ -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):
@ -105,12 +105,24 @@ class TestDeprecatedCall(object):
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):
@ -181,4 +193,3 @@ class TestWarns(object):
''')
result = testdir.runpytest()
result.stdout.fnmatch_lines(['*2 passed in*'])