Skip to content

Commit 0a6d48d

Browse files
author
MarcoFalke
committed
Merge #9168: [qa] add assert_raises_message to check specific error message
307acdd [qa] add assert_raises_message to check specific error message (mrbandrews)
2 parents 434e683 + 307acdd commit 0a6d48d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

qa/rpc-tests/test_framework/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,14 @@ def assert_greater_than(thing1, thing2):
531531
raise AssertionError("%s <= %s"%(str(thing1),str(thing2)))
532532

533533
def assert_raises(exc, fun, *args, **kwds):
534+
assert_raises_message(exc, None, fun, *args, **kwds)
535+
536+
def assert_raises_message(exc, message, fun, *args, **kwds):
534537
try:
535538
fun(*args, **kwds)
536-
except exc:
537-
pass
539+
except exc as e:
540+
if message is not None and message not in e.error['message']:
541+
raise AssertionError("Expected substring not found:"+e.error['message'])
538542
except Exception as e:
539543
raise AssertionError("Unexpected exception raised: "+type(e).__name__)
540544
else:

qa/rpc-tests/wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run_test (self):
7171
unspent_0 = self.nodes[2].listunspent()[0]
7272
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
7373
self.nodes[2].lockunspent(False, [unspent_0])
74-
assert_raises(JSONRPCException, self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20)
74+
assert_raises_message(JSONRPCException, "Insufficient funds", self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20)
7575
assert_equal([unspent_0], self.nodes[2].listlockunspent())
7676
self.nodes[2].lockunspent(True, [unspent_0])
7777
assert_equal(len(self.nodes[2].listlockunspent()), 0)

0 commit comments

Comments
 (0)