Skip to content

test(python): one assertion per line and one raising call per pytest.raises - #2148

Merged
HuiJun merged 2 commits into
developfrom
refactor/sonar-python-tests
Nov 12, 2026
Merged

HuiJun merged 2 commits into
developfrom
refactor/sonar-python-tests

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What and why

SonarCloud's analysis of develop reports 14 open findings in the Python client tests: 12 composite assertions (python:S9073, "Split this composite assertion into separate assertions") and 2 pytest.raises blocks holding more than one call that could raise (python:S5778, "Refactor this exception test to have only one invocation possibly throwing an exception"). This fixes each at the source; nothing is suppressed and no expectation changes.

python:S9073 — composite assert a and b split into one assert per operand (every operand stays asserted, in the same order, so a failure now names the operand that failed instead of the whole chain):

  • client/python/tests/test_element_properties.py
    • test_a_response_decodes_as_a_mapping_of_properties: the len(read) == 4 and "isAbstract" in read and "name" not in read chain, the defining_class/many/derived chain, the isAbstract value/many chain and the ownedSubclassification supported/falsy chain (4 findings)
    • test_every_value_arm_decodes_to_its_python_value: the identity == … and str(identity) == … chain
    • test_the_connection_sends_the_element_and_the_names: the model_hash/element_id chain and the isinstance … and qualified_name chain
    • test_an_unnamed_connector_is_read_by_position_and_walked_by_form_id: the metaclass … and qualified_name == "" chain
    • test_why_a_property_has_no_answer_is_said: the supported and len(values) == 1 chain
    • test_every_inherited_membership_and_its_member_read_back: the per-membership id … and metaclass chain and the final len(unnamed) >= 18 and … in unnamed and … in unnamed chain
  • client/python/tests/test_unnamed_children.py
    • test_children_list_every_member_the_query_reports: the anonymous is not None and kind == … and name == "" chain (the is not None assert still runs first, so the attribute reads are guarded exactly as before)

python:S5778 — only the call under test inside pytest.raises (the construction moves to a local above the block, so a ValueError/RuntimeError from the constructor would now fail the test instead of satisfying it):

  • client/python/tests/test_element_properties.py test_the_model_and_the_symbol_reach_the_connection: Symbol(sysml_pb2.SymbolInfo(id="EP::Pair"), None, "hash1") is built as unconnected; the with pytest.raises(ValueError) block holds only unconnected.properties()
  • client/python/tests/test_instance.py test_paths_needs_the_connection: Instance(vehicle, graph) is built as root; the with pytest.raises(RuntimeError, match="connection") block holds only root.paths()

Test-only change; no production code, documentation or changelog entry is affected.

How it was verified

  • make build-grpc, then cd client/python && OPENSYSML_REQUIRE_SERVICE=1 pytest tests/ -q against a bin/sysml-grpc -port 50051 started as the CI job does: 1780 passed, 5 skipped (the three touched files: 39 passed, 0 skipped, so the service-backed @pytest.mark.integration tests ran rather than skipped)
  • go build ./... && go vet ./... && test -z "$(gofmt -l .)" && make lint clean; go test -count=1 ./tests/hygiene and make test-quick SHARDS="grpc" pass (no Go file changes)
  • python3 scripts/check-doc-ids.py and python3 scripts/changelog.py check clean
  • Dry merge (git merge-tree --write-tree) against the open PRs that also edit test_element_properties.py, feat(grpc): GetElementProperties reads the symbol-backed metamodel structure #2042 and fix(grpc): GetElementProperties reads a model one document at a time #2052: no conflict in any client/python/tests file; the conflicts those merges report are exactly the ones each PR already has against origin/develop

Checklist

  • make test and make lint pass locally
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md) — not applicable, test-only
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md — not applicable, test-only
  • baselines regenerated and make docs-counts run if a gate count moved — no gate count moved
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/c85391e5049643fa9cc5a7d381fd85d8
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/c85391e5049643fa9cc5a7d381fd85d8?variant=devin
Requested by: @HuiJun


🟢 Devin Review found nothing to fix · View findings

Devin Review

…raises

Splits the composite assert-and chains in the element-properties, instance and unnamed-children tests into one assert per operand, and builds the Symbol and Instance under test before the pytest.raises block so only the call expected to raise sits inside it.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@HuiJun
HuiJun added this pull request to the merge queue Nov 12, 2026
Merged via the queue into develop with commit 6d7114e Nov 12, 2026
22 of 44 checks passed
@HuiJun
HuiJun deleted the refactor/sonar-python-tests branch November 12, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant