[AAASM-4691] ✅ (python-sdk): Fix pytest.raises single-statement smells (S5778)#264
Merged
Merged
Conversation
S5778: keep only the single raising call inside the with-block by constructing the adapter (and its argument) beforehand.
S5778: hoist run_id=uuid4() and the recorder construction out of the pytest.raises blocks so each wraps a single call.
S5778: extract the uuid4() call before each with pytest.raises so only handler.on_tool_start remains inside.
S5778: construct tool/ctx/args before each pytest.raises block so only the awaited _run/run call remains inside.
S5778: bind the tool instance before each pytest.raises so only the awaited invoke() call remains inside.
S5778: bind the SimpleNamespace ctx / MagicMock args before each pytest.raises so only the awaited invoke/run call remains inside.
S5778: bind the session before pytest.raises so only the awaited call_tool() remains inside.
S5778: the combined pytest.raises/spawn_context_scope with-block held two statements. Move the scope and raise into a nested helper so the RuntimeError still propagates through spawn_context_scope.__exit__ (exercising the reset-on-exception path) while pytest.raises wraps a single call.
S5778: bind the path before pytest.raises so only load_adapter_class_from_path() remains inside.
|
Contributor
Author
🤖 Claude Code review
Automated review by Claude Code. |
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.



Description
Resolves all 28 SonarCloud
python:S5778code smells ("thepytest.raises/assertRaisesblock should contain a single simple statement") across thetest/suite. For each flagged block, the setup calls that produce arguments orinstances (constructors,
uuid4(),MagicMock(),SimpleNamespace(...),_ArgsModel(...),str(...)) were hoisted before thewith pytest.raises(...)block, leaving only the single call expected to raise inside it.
The one combined-context-manager case
(
test_spawn_lineage_integration.py::test_exception_in_scope_still_resets_ctx,which had both
pytest.raisesandspawn_context_scope(ctx)plus two bodystatements) was refactored to move the scope +
raiseinto a nested helper, sothe
RuntimeErrorstill propagates throughspawn_context_scope.__exit__(exercising the reset-on-exception path) while
pytest.raiseswraps a singlecall. No assertions were weakened or removed.
Type of Change
Breaking Changes
Related Issues
Testing
.venv/bin/python -m pytest test/→ 800 passed, 15 skippedruff check+ruff format --checkon all changed files → cleanChecklist
🤖 Generated with Claude Code