allow error message matching in pytest.raises
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user