mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-25 21:39:05 +01:00
[Tests] Require exact match in assert_start_raises_init_eror()
This commit is contained in:
@@ -169,8 +169,11 @@ class TestNode():
|
||||
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *args, **kwargs):
|
||||
"""Attempt to start the node and expect it to raise an error.
|
||||
|
||||
extra_args: extra arguments to pass through to bitcoind
|
||||
expected_msg: regex that stderr should match when bitcoind fails
|
||||
|
||||
Will throw if bitcoind starts without an error.
|
||||
Will throw if an expected_msg is provided and it does not appear in bitcoind's stdout."""
|
||||
Will throw if an expected_msg is provided and it does not match bitcoind's stdout."""
|
||||
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
|
||||
try:
|
||||
self.start(extra_args, stderr=log_stderr, *args, **kwargs)
|
||||
@@ -181,11 +184,12 @@ class TestNode():
|
||||
assert 'bitcoind exited' in str(e) # node must have shutdown
|
||||
self.running = False
|
||||
self.process = None
|
||||
# Check stderr for expected message
|
||||
if expected_msg is not None:
|
||||
log_stderr.seek(0)
|
||||
stderr = log_stderr.read().decode('utf-8')
|
||||
if expected_msg not in stderr:
|
||||
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
|
||||
if re.fullmatch(expected_msg + '\n', stderr) is None:
|
||||
raise AssertionError('Expected message "{}" does not match stderr:\n"{}"'.format(expected_msg, stderr))
|
||||
else:
|
||||
if expected_msg is None:
|
||||
assert_msg = "bitcoind should have exited with an error"
|
||||
|
||||
Reference in New Issue
Block a user