[qa] add assert_raises_message to check specific error message

Github-Pull: #9168
Rebased-From: 307acdd3df03082295ac0f7fe9eba7dd35973bc4
This commit is contained in:
mrbandrews
2016-11-15 15:37:46 -05:00
committed by MarcoFalke
parent 9460771a60
commit 3107280e14
2 changed files with 7 additions and 3 deletions

View File

@@ -508,10 +508,14 @@ def assert_greater_than(thing1, thing2):
raise AssertionError("%s <= %s"%(str(thing1),str(thing2)))
def assert_raises(exc, fun, *args, **kwds):
assert_raises_message(exc, None, fun, *args, **kwds)
def assert_raises_message(exc, message, fun, *args, **kwds):
try:
fun(*args, **kwds)
except exc:
pass
except exc as e:
if message is not None and message not in e.error['message']:
raise AssertionError("Expected substring not found:"+e.error['message'])
except Exception as e:
raise AssertionError("Unexpected exception raised: "+type(e).__name__)
else: