allow error message matching in pytest.raises

This commit is contained in:
Thomas Kriechbaumer
2017-02-01 13:37:13 +01:00
parent 3b47cb45e6
commit 43662ce789
4 changed files with 40 additions and 6 deletions

View File

@@ -118,3 +118,18 @@ class TestRaises:
for o in gc.get_objects():
assert type(o) is not T
def test_raises_match(self):
msg = r"with base \d+"
with pytest.raises(ValueError, match=msg):
int('asdf')
msg = "with base 10"
with pytest.raises(ValueError, match=msg):
int('asdf')
msg = "with base 16"
expr = r"Pattern '{}' not found in 'invalid literal for int\(\) with base 10: 'asdf''".format(msg)
with pytest.raises(AssertionError, match=expr):
with pytest.raises(ValueError, match=msg):
int('asdf', base=10)