diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -326,33 +326,33 @@ with open(debug_log, encoding='utf-8') as dl: dl.seek(0, 2) prev_size = dl.tell() - try: - yield - finally: - while True: - found = True - with open(debug_log, encoding='utf-8') as dl: - dl.seek(prev_size) - log = dl.read() - print_log = " - " + "\n - ".join(log.splitlines()) - for unexpected_msg in unexpected_msgs: - if re.search(re.escape(unexpected_msg), - log, flags=re.MULTILINE): - self._raise_assertion_error( - 'Unexpected message "{}" partially matches log:\n\n{}\n\n'.format( - unexpected_msg, print_log)) - for expected_msg in expected_msgs: - if re.search(re.escape(expected_msg), log, - flags=re.MULTILINE) is None: - found = False - if found: - return - if time.time() >= time_end: - break - time.sleep(0.05) - self._raise_assertion_error( - 'Expected messages "{}" does not partially match log:\n\n{}\n\n'.format( - str(expected_msgs), print_log)) + + yield + + while True: + found = True + with open(debug_log, encoding='utf-8') as dl: + dl.seek(prev_size) + log = dl.read() + print_log = " - " + "\n - ".join(log.splitlines()) + for unexpected_msg in unexpected_msgs: + if re.search(re.escape(unexpected_msg), + log, flags=re.MULTILINE): + self._raise_assertion_error( + 'Unexpected message "{}" partially matches log:\n\n{}\n\n'.format( + unexpected_msg, print_log)) + for expected_msg in expected_msgs: + if re.search(re.escape(expected_msg), log, + flags=re.MULTILINE) is None: + found = False + if found: + return + if time.time() >= time_end: + break + time.sleep(0.05) + self._raise_assertion_error( + 'Expected messages "{}" does not partially match log:\n\n{}\n\n'.format( + str(expected_msgs), print_log)) def assert_start_raises_init_error( self, extra_args=None, expected_msg=None, match=ErrorMatch.FULL_TEXT, *args, **kwargs):