Skip to content

Commit 075352e

Browse files
committed
qa: assert_raises_message() - search in str(e)
repr() is annoying because it requires escaping special characters, use str() instead. Original discussion: bitcoin/bitcoin#30660 (comment)
1 parent bd8ebbc commit 075352e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

test/functional/feature_framework_startup_failures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ def run_test(self):
6969
self.log.info("Verifying _verify_startup_failure() functionality (self-check).")
7070
assert_raises_message(
7171
AssertionError,
72-
("Child test didn't contain (only) expected errors:\n" +
73-
linesep.join(["Found 0/1 tracebacks - expecting exactly one with no knock-on exceptions.",
74-
"Found 0/1 occurrences of the specific exception: NonExistentError",
75-
"Found 0/1 test failure output messages."])).encode("unicode_escape").decode("utf-8"),
72+
( "Child test didn't contain (only) expected errors:\n"
73+
f"Found 0/1 tracebacks - expecting exactly one with no knock-on exceptions.{linesep}"
74+
f"Found 0/1 occurrences of the specific exception: NonExistentError{linesep}"
75+
"Found 0/1 test failure output messages."),
7676
self._verify_startup_failure,
7777
TestSuccess, [],
7878
"NonExistentError",

test/functional/test_framework/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def assert_raises_message(exc, message, fun, *args, **kwds):
101101
except JSONRPCException:
102102
raise AssertionError("Use assert_raises_rpc_error() to test RPC failures")
103103
except exc as e:
104-
if message is not None and message not in repr(e):
104+
if message is not None and message not in str(e):
105105
raise AssertionError("Expected substring not found in exception:\n"
106-
f"substring: '{message}'\nexception: {repr(e)}.")
106+
f"substring: '{message}'\nexception: {e!r}.")
107107
except Exception as e:
108108
raise AssertionError("Unexpected exception raised: " + type(e).__name__)
109109
else:

0 commit comments

Comments
 (0)