Add test to design warns signature in TDD mimicking raises signature
This commit is contained in:
parent
5c0feb2877
commit
d8ecca5ebd
|
@ -284,3 +284,25 @@ class TestWarns(object):
|
||||||
''')
|
''')
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines(['*2 passed in*'])
|
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)
|
||||||
|
|
Loading…
Reference in New Issue