summaryrefslogtreecommitdiff
path: root/testing/test_recwarn.py
diff options
context:
space:
mode:
authorJoan Massich <sik@visor.udg.edu>2017-08-22 13:48:29 +0200
committerJoan Massich <sik@visor.udg.edu>2017-09-04 15:26:00 +0200
commitd8ecca5ebd929f1be49033f8a06eed97494af3da (patch)
tree4a57ba97ac8ed6ca6038eb37a23b79f8592e5a3e /testing/test_recwarn.py
parent5c0feb287702ca4090ac949301c6217c77798f51 (diff)
downloadpytest-d8ecca5ebd929f1be49033f8a06eed97494af3da.tar.gz
Add test to design warns signature in TDD mimicking raises signature
Diffstat (limited to 'testing/test_recwarn.py')
-rw-r--r--testing/test_recwarn.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py
index 6895b1140..e4e7934cc 100644
--- a/testing/test_recwarn.py
+++ b/testing/test_recwarn.py
@@ -284,3 +284,25 @@ class TestWarns(object):
''')
result = testdir.runpytest()
result.stdout.fnmatch_lines(['*2 passed in*'])
+
+ def test_match_regex(self):
+ with pytest.warns(UserWarning, match=r'must be \d+$'):
+ warnings.warn("value must be 42", UserWarning)
+
+ with pytest.raises(AssertionError, match='pattern not found'):
+ with pytest.warns(UserWarning, match=r'must be \d+$'):
+ warnings.warn("this is not here", UserWarning)
+
+ def test_one_from_multiple_warns():
+ with warns(UserWarning, match=r'aaa'):
+ warnings.warn("cccccccccc", UserWarning)
+ warnings.warn("bbbbbbbbbb", UserWarning)
+ warnings.warn("aaaaaaaaaa", UserWarning)
+
+ def test_none_of_multiple_warns():
+ a, b, c = ('aaa', 'bbbbbbbbbb', 'cccccccccc')
+ expected_msg = "'{}' pattern not found in \['{}', '{}'\]".format(a, b, c)
+ with raises(AssertionError, match=expected_msg):
+ with warns(UserWarning, match=r'aaa'):
+ warnings.warn("bbbbbbbbbb", UserWarning)
+ warnings.warn("cccccccccc", UserWarning)