Raising a new exception from within a Python except
-block causes the interpreter to generate extra error output which is unnecessary in this case.
Found while testing #32835 using the suggested method (https://github.com/bitcoin/bitcoin/pull/32835#issue-3188748624) which triggered expected timeouts, but with the extra error noise.
Before:
02025-07-08T20:05:48.407001Z TestFramework (ERROR): Assertion failed
1Traceback (most recent call last):
2 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 686, in assert_start_raises_init_error
3 ret = self.process.wait(timeout=self.rpc_timeout)
4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 File "/nix/store/fqm9bqqlmaqqr02qbalm1bazp810qfiw-python3-3.12.9/lib/python3.12/subprocess.py", line 1266, in wait
6 return self._wait(timeout=timeout)
7 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 File "/nix/store/fqm9bqqlmaqqr02qbalm1bazp810qfiw-python3-3.12.9/lib/python3.12/subprocess.py", line 2053, in _wait
9 raise TimeoutExpired(self.args, timeout)
10subprocess.TimeoutExpired: Command '['/home/hodlinator/bitcoin/build/bin/bitcoind', '-datadir=/tmp/bitcoin_func_test_v96lkcq8/eb2665c7/node0', '-logtimemicros', '-debug', '-debugexclude=libevent', '-debugexclude=leveldb', '-debugexclude=rand', '-uacomment=testnode0', '-disablewallet', '-logthreadnames', '-logsourcelocations', '-loglevel=trace', '-v2transport=0']' timed out after 3 seconds
11
12During handling of the above exception, another exception occurred:
13
14Traceback (most recent call last):
15 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 186, in main
16 self.setup()
17 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 358, in setup
18 self.setup_network()
19 File "/home/hodlinator/bitcoin/build/test/functional/feature_framework_startup_failures.py", line 151, in setup_network
20 self.nodes[0].assert_start_raises_init_error()
21 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 716, in assert_start_raises_init_error
22 self._raise_assertion_error(assert_msg)
23 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 196, in _raise_assertion_error
24 raise AssertionError(self._node_msg(msg))
25AssertionError: [node 0] bitcoind should have exited within 3s with an error
After:
02025-07-08T20:09:15.330589Z TestFramework (ERROR): Assertion failed
1Traceback (most recent call last):
2 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 186, in main
3 self.setup()
4 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 358, in setup
5 self.setup_network()
6 File "/home/hodlinator/bitcoin/build/test/functional/feature_framework_startup_failures.py", line 151, in setup_network
7 self.nodes[0].assert_start_raises_init_error()
8 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 720, in assert_start_raises_init_error
9 self._raise_assertion_error(assert_msg)
10 File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 196, in _raise_assertion_error
11 raise AssertionError(self._node_msg(msg))
12AssertionError: [node 0] bitcoind should have exited within 3s with an error
Can be tested by:
- Execute test containing new test case:
0build/test/functional/feature_framework_startup_failures.py -ldebug > after.log
- Drop first commit which contains the fix.
- Re-run test:
0build/test/functional/feature_framework_startup_failures.py -ldebug > before.log
- Diff logs, focusing on
TestInitErrorTimeout OUTPUT
sections.