From 075352ec8e573c0dd819202d223eed5209c9e4bf Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Wed, 14 May 2025 16:19:23 +0200 Subject: [PATCH] qa: assert_raises_message() - search in str(e) repr() is annoying because it requires escaping special characters, use str() instead. Original discussion: https://github.com/bitcoin/bitcoin/pull/30660#discussion_r2080292165 --- test/functional/feature_framework_startup_failures.py | 8 ++++---- test/functional/test_framework/util.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/functional/feature_framework_startup_failures.py b/test/functional/feature_framework_startup_failures.py index f84fcdc38f0..f092f07e0ed 100755 --- a/test/functional/feature_framework_startup_failures.py +++ b/test/functional/feature_framework_startup_failures.py @@ -69,10 +69,10 @@ class FeatureFrameworkStartupFailures(BitcoinTestFramework): self.log.info("Verifying _verify_startup_failure() functionality (self-check).") assert_raises_message( AssertionError, - ("Child test didn't contain (only) expected errors:\n" + - linesep.join(["Found 0/1 tracebacks - expecting exactly one with no knock-on exceptions.", - "Found 0/1 occurrences of the specific exception: NonExistentError", - "Found 0/1 test failure output messages."])).encode("unicode_escape").decode("utf-8"), + ( "Child test didn't contain (only) expected errors:\n" + f"Found 0/1 tracebacks - expecting exactly one with no knock-on exceptions.{linesep}" + f"Found 0/1 occurrences of the specific exception: NonExistentError{linesep}" + "Found 0/1 test failure output messages."), self._verify_startup_failure, TestSuccess, [], "NonExistentError", diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index b2f765e4d12..70d68ea7303 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -101,9 +101,9 @@ def assert_raises_message(exc, message, fun, *args, **kwds): except JSONRPCException: raise AssertionError("Use assert_raises_rpc_error() to test RPC failures") except exc as e: - if message is not None and message not in repr(e): + if message is not None and message not in str(e): raise AssertionError("Expected substring not found in exception:\n" - f"substring: '{message}'\nexception: {repr(e)}.") + f"substring: '{message}'\nexception: {e!r}.") except Exception as e: raise AssertionError("Unexpected exception raised: " + type(e).__name__) else: