From fb43b2f8cc4ce53315fd3c84c6a8457388664ddf Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Wed, 3 Dec 2025 21:23:51 +0100 Subject: [PATCH] qa: Improve assert_start_raises_init_error output Re-raising within the except-block would trigger excessive "During handling of the above exception, another exception occurred"-output. Also changed comment - exceptions are raised in Python, not thrown. --- test/functional/test_framework/test_node.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 060a932d1c8..674513bf6d8 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -712,11 +712,12 @@ class TestNode(): 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 match bitcoind's stdout.""" + Will raise if bitcoind starts without an error. + Will raise if an expected_msg is provided and it does not match bitcoind's stdout.""" assert not self.running with tempfile.NamedTemporaryFile(dir=self.stderr_dir, delete=False) as log_stderr, \ tempfile.NamedTemporaryFile(dir=self.stdout_dir, delete=False) as log_stdout: + assert_msg = None try: self.start(extra_args, stdout=log_stdout, stderr=log_stderr, *args, **kwargs) ret = self.process.wait(timeout=self.rpc_timeout) @@ -740,7 +741,7 @@ class TestNode(): if expected_msg != stderr: self._raise_assertion_error( 'Expected message "{}" does not fully match stderr:\n"{}"'.format(expected_msg, stderr)) - except subprocess.TimeoutExpired: + except subprocess.TimeoutExpired as e: self.process.kill() self.running = False self.process = None @@ -749,6 +750,10 @@ class TestNode(): assert_msg += "with an error" else: assert_msg += "with expected error " + expected_msg + assert_msg += f" (cmd: {e.cmd})" + + # Raise assertion outside of except-block above in order for it not to be treated as a knock-on exception. + if assert_msg: self._raise_assertion_error(assert_msg) def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=True, supports_v2_p2p=None, wait_for_v2_handshake=True, expect_success=True, **kwargs):