diff options
author | Anthony Sottile <asottile@umich.edu> | 2018-10-10 08:00:59 -0700 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2018-10-10 08:03:23 -0700 |
commit | aeb92accb2521f1f1ccc4faaf9e6f6bd36e04d8b (patch) | |
tree | 0fe28ebadb939d6aca12c5709ab328d1469f58c0 /testing/test_recwarn.py | |
parent | 943bbdd8cedfd5cf63a9274aedeb4777e314c162 (diff) | |
download | pytest-aeb92accb2521f1f1ccc4faaf9e6f6bd36e04d8b.tar.gz |
Implement pytest.deprecated_call with pytest.warns
Diffstat (limited to 'testing/test_recwarn.py')
-rw-r--r-- | testing/test_recwarn.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index 82bd66c55..897f4c5e8 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -76,9 +76,8 @@ class TestDeprecatedCall(object): ) def test_deprecated_call_raises(self): - with pytest.raises(AssertionError) as excinfo: + with pytest.raises(pytest.fail.Exception, match="No warnings of type"): pytest.deprecated_call(self.dep, 3, 5) - assert "Did not produce" in str(excinfo) def test_deprecated_call(self): pytest.deprecated_call(self.dep, 0, 5) @@ -100,7 +99,7 @@ class TestDeprecatedCall(object): assert warn_explicit is warnings.warn_explicit def test_deprecated_explicit_call_raises(self): - with pytest.raises(AssertionError): + with pytest.raises(pytest.fail.Exception): pytest.deprecated_call(self.dep_explicit, 3) def test_deprecated_explicit_call(self): @@ -116,8 +115,8 @@ class TestDeprecatedCall(object): def f(): pass - msg = "Did not produce DeprecationWarning or PendingDeprecationWarning" - with pytest.raises(AssertionError, match=msg): + msg = "No warnings of type (.*DeprecationWarning.*, .*PendingDeprecationWarning.*)" + with pytest.raises(pytest.fail.Exception, match=msg): if mode == "call": pytest.deprecated_call(f) else: @@ -179,12 +178,20 @@ class TestDeprecatedCall(object): def f(): warnings.warn(warning("hi")) - with pytest.raises(AssertionError): + with pytest.raises(pytest.fail.Exception): pytest.deprecated_call(f) - with pytest.raises(AssertionError): + with pytest.raises(pytest.fail.Exception): with pytest.deprecated_call(): f() + def test_deprecated_call_supports_match(self): + with pytest.deprecated_call(match=r"must be \d+$"): + warnings.warn("value must be 42", DeprecationWarning) + + with pytest.raises(pytest.fail.Exception): + with pytest.deprecated_call(match=r"must be \d+$"): + warnings.warn("this is not here", DeprecationWarning) + class TestWarns(object): def test_strings(self): |