From ae4730ea128e2fefab3247e3e6fbfda91dea9383 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:23:51 +0100 Subject: [PATCH] qa: Add assert_true() This follows the style of ASSERT_TRUE() in GoogleTest: https://google.github.io/googletest/reference/assertions.html --- test/functional/test_framework/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 14930ef6719..598329e423a 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -69,6 +69,14 @@ def summarise_dict_differences(thing1, thing2): d2[k] = thing2[k] return d1, d2 + +def assert_true(condition: bool) -> None: + """Separate from the `assert` keyword in that it should not be optimized out + when environment var `PYTHONOPTIMIZE=1`, or Python is run with `-O`.""" + if not condition: + raise AssertionError + + def assert_equal(thing1, thing2, *args): if thing1 != thing2 and not args and isinstance(thing1, dict) and isinstance(thing2, dict): d1,d2 = summarise_dict_differences(thing1, thing2)