From 8f5e230a4069a4355688633360c1d0b4d137e4b4 Mon Sep 17 00:00:00 2001 From: mercael91 Date: Sun, 8 Nov 2026 04:51:20 +0300 Subject: [PATCH 1/3] Add assertion messages to decorators checks and regression test Signed-off-by: mercael91 --- checks/decorators/decorators2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/checks/decorators/decorators2.py b/checks/decorators/decorators2.py index 3792dc6..1338291 100644 --- a/checks/decorators/decorators2.py +++ b/checks/decorators/decorators2.py @@ -1,5 +1,7 @@ assert loud_greet() == "HELLO", ( f"loud_greet() should return 'HELLO', got {loud_greet()!r}" ) -assert shout(lambda: "world")() == "WORLD" +assert shout(lambda: "world")() == "WORLD", ( + f"shout(lambda: 'world')() should return 'WORLD', got {shout(lambda: 'world')()!r}" +) print("decorators2 ✓") From f9856689b6f77b0e71e3c0b2a14d960f0a37cce0 Mon Sep 17 00:00:00 2001 From: mercael91 Date: Sun, 8 Nov 2026 04:51:21 +0300 Subject: [PATCH 2/3] Add assertion messages to decorators checks and regression test Signed-off-by: mercael91 --- checks/decorators/decorators5.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/checks/decorators/decorators5.py b/checks/decorators/decorators5.py index facfe56..997a53d 100644 --- a/checks/decorators/decorators5.py +++ b/checks/decorators/decorators5.py @@ -1,5 +1,9 @@ assert add(3, 4) == 7, f"add(3, 4) should return 7, got {add(3, 4)!r}" -assert add(10, -2) == 8 -assert greet("Alice") == "Hello, Alice!" -assert greet("Bob", greeting="Hi") == "Hi, Bob!" +assert add(10, -2) == 8, f"add(10, -2) should return 8, got {add(10, -2)!r}" +assert greet("Alice") == "Hello, Alice!", ( + f"greet('Alice') should return 'Hello, Alice!', got {greet('Alice')!r}" +) +assert greet("Bob", greeting="Hi") == "Hi, Bob!", ( + f"greet('Bob', greeting='Hi') should return 'Hi, Bob!', got {greet('Bob', greeting='Hi')!r}" +) print("decorators5 ✓") From 9fca2415b3fe7ac88f7bf941005909cb90b6383c Mon Sep 17 00:00:00 2001 From: mercael91 Date: Sun, 8 Nov 2026 04:51:22 +0300 Subject: [PATCH 3/3] Add assertion messages to decorators checks and regression test Signed-off-by: mercael91 --- tests/test_decorators_assertion_messages.py | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/test_decorators_assertion_messages.py diff --git a/tests/test_decorators_assertion_messages.py b/tests/test_decorators_assertion_messages.py new file mode 100644 index 0000000..c68f242 --- /dev/null +++ b/tests/test_decorators_assertion_messages.py @@ -0,0 +1,22 @@ +import ast +from pathlib import Path + + +CHECKS = Path(__file__).resolve().parent.parent / "checks" / "decorators" + + +def _asserts_without_msg(path): + tree = ast.parse(path.read_text()) + missing = [] + for node in ast.walk(tree): + if isinstance(node, ast.Assert) and node.msg is None: + missing.append(node.lineno) + return missing + + +def test_decorators2_asserts_have_messages(): + assert _asserts_without_msg(CHECKS / "decorators2.py") == [] + + +def test_decorators5_asserts_have_messages(): + assert _asserts_without_msg(CHECKS / "decorators5.py") == []