Skip to content

Commit d8ecca5

Browse files
author
Joan Massich
committed
Add test to design warns signature in TDD mimicking raises signature
1 parent 5c0feb2 commit d8ecca5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

testing/test_recwarn.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,25 @@ def test(run):
284284
''')
285285
result = testdir.runpytest()
286286
result.stdout.fnmatch_lines(['*2 passed in*'])
287+
288+
def test_match_regex(self):
289+
with pytest.warns(UserWarning, match=r'must be \d+$'):
290+
warnings.warn("value must be 42", UserWarning)
291+
292+
with pytest.raises(AssertionError, match='pattern not found'):
293+
with pytest.warns(UserWarning, match=r'must be \d+$'):
294+
warnings.warn("this is not here", UserWarning)
295+
296+
def test_one_from_multiple_warns():
297+
with warns(UserWarning, match=r'aaa'):
298+
warnings.warn("cccccccccc", UserWarning)
299+
warnings.warn("bbbbbbbbbb", UserWarning)
300+
warnings.warn("aaaaaaaaaa", UserWarning)
301+
302+
def test_none_of_multiple_warns():
303+
a, b, c = ('aaa', 'bbbbbbbbbb', 'cccccccccc')
304+
expected_msg = "'{}' pattern not found in \['{}', '{}'\]".format(a, b, c)
305+
with raises(AssertionError, match=expected_msg):
306+
with warns(UserWarning, match=r'aaa'):
307+
warnings.warn("bbbbbbbbbb", UserWarning)
308+
warnings.warn("cccccccccc", UserWarning)

0 commit comments

Comments
 (0)