test(vars): assert real error messages in computed var tests#6750
Open
anxkhn wants to merge 1 commit into
Open
test(vars): assert real error messages in computed var tests#6750anxkhn wants to merge 1 commit into
anxkhn wants to merge 1 commit into
Conversation
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>
Contributor
Greptile SummaryThis PR makes two computed-var error-message checks execute correctly. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "test(vars): assert real error messages i..." | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two computed-var error tests in
tests/units/test_var.pyplaced their messageassertions inside the
with pytest.raises(...)block, on the line right afterthe statement that raises:
test_computed_var_without_annotation_errortest_computed_var_with_annotation_errorBecause the preceding line raises, control leaves the
withblock immediately,so the assertion lines were never reached. On top of that,
err.valueis onlypopulated after the block exits, so the in-block assertions could not have run
even structurally. Both asserted strings were also stale and no longer matched
the messages the code raises, so a regressed or wrong error message would still
pass CI.
Fix
Move each assertion out of the
raisesblock and compare against the message thecode actually raises:
UntypedComputedVarError(aTypeError), asserted exactly:"Computed var 'var_without_annotation' must have a type annotation."VarAttributeError(anAttributeError). The messagebegins with a dynamic state-var path, so the test matches on the stable suffix
via
str.endswith(...):"of type <class 'str'> has no attribute 'foo' or may have been annotated wrongly."(Both parametrized fixtures declare the computed var as
-> str, so<class 'str'>is correct.)This is a test-only change; no framework behavior changes.
Testing
uv run pytest tests/units/test_var.py::test_computed_var_without_annotation_error tests/units/test_var.py::test_computed_var_with_annotation_error-> 4 passeduv run pytest tests/units/test_var.py-> 204 passeduv run ruff check tests/units/test_var.pyanduv run ruff format --check tests/units/test_var.py-> cleanuv run pyright tests/units/test_var.py-> 0 errorsbreaking the real source messages makes the corrected tests fail, whereas the
original (pre-fix) assertions still passed against the same broken source,
confirming they were dead code.