From f34e572a54e1786caac042fb21177478f19664de Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:37:15 +0530 Subject: [PATCH] test(vars): assert real error messages in computed var tests The message assertions in test_computed_var_without_annotation_error and test_computed_var_with_annotation_error sat inside the with pytest.raises(...) block, after the line that raises, so they were unreachable and err.value was not yet populated. Both asserted strings were also stale and no longer matched the raised messages, so a regressed error message would still pass. Move each assertion out of the raises block and compare against the messages the code actually raises: UntypedComputedVarError for the unannotated case, and the VarAttributeError text for the wrongly annotated case (matched on its stable suffix, since the state-var prefix is dynamic). Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --- tests/units/test_var.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/units/test_var.py b/tests/units/test_var.py index c7a64902084..1bb03eae9a1 100644 --- a/tests/units/test_var.py +++ b/tests/units/test_var.py @@ -782,11 +782,10 @@ def test_computed_var_without_annotation_error(request, fixture): with pytest.raises(TypeError) as err: state = request.getfixturevalue(fixture) state.var_without_annotation.foo - full_name = state.var_without_annotation._var_full_name - assert ( - err.value.args[0] - == f"You must provide an annotation for the state var `{full_name}`. Annotation cannot be `typing.Any`" - ) + assert ( + err.value.args[0] + == "Computed var 'var_without_annotation' must have a type annotation." + ) @pytest.mark.parametrize( @@ -827,11 +826,9 @@ def test_computed_var_with_annotation_error(request, fixture): with pytest.raises(AttributeError) as err: state = request.getfixturevalue(fixture) state.var_with_annotation.foo - full_name = state.var_with_annotation._var_full_name - assert ( - err.value.args[0] - == f"The State var `{full_name}` has no attribute 'foo' or may have been annotated wrongly." - ) + assert err.value.args[0].endswith( + "of type has no attribute 'foo' or may have been annotated wrongly." + ) @pytest.mark.parametrize(