pytest.raises accept cutom message only when used as context manager

This commit is contained in:
palaviv
2016-06-19 21:24:47 +03:00
parent e6ff01ada3
commit ca093673fb
2 changed files with 10 additions and 8 deletions

View File

@@ -76,20 +76,23 @@ class TestRaises:
pytest.raises(ValueError, int, '0')
except pytest.raises.Exception as e:
assert e.msg == "DID NOT RAISE {0}".format(repr(ValueError))
else:
assert False, "Expected pytest.raises.Exception"
try:
with pytest.raises(ValueError):
pass
except pytest.raises.Exception as e:
assert e.msg == "DID NOT RAISE {0}".format(repr(ValueError))
else:
assert False, "Expected pytest.raises.Exception"
def test_costum_raise_message(self):
message = "TEST_MESSAGE"
try:
pytest.raises(ValueError, int, '0', message=message)
except pytest.raises.Exception as e:
assert e.msg == message
try:
with pytest.raises(ValueError, message=message):
pass
except pytest.raises.Exception as e:
assert e.msg == message
else:
assert False, "Expected pytest.raises.Exception"