Skip to content

tests/: split composite assertions and replace manual sys.path mutation with monkeypatch (SonarCloud S9073, S8997) #115

Closed

Description

@brettheap

Lane: openreposhape-2 (openRepoShape-2)

What is wrong. SonarCloud flags 30 sites in tests/, two rules:

python:S9073 "Split this composite assertion into separate assertions" (22
sites) — an assert a and b (or a and b, msg) hides which half failed, so a
red run in CI shows only AssertionError with no way to tell a from b
without opening the file:

  • tests/test_scaffold_e2e.py:280,282,574,732,755,773,788
  • tests/test_family.py:231,234,909,978,1166
  • tests/test_shape_doctor.py:779,883,1518
  • tests/test_repo_hygiene.py:152,1172
  • tests/test_free_plan_hint.py:68
  • tests/test_openreposhape_command.py:734
  • tests/test_setup_project_py.py:1054
  • tests/test_setup_sh.py:168
  • tests/test_update_shape_add.py:459

python:S8997 "Use the monkeypatch fixture for temporary modifications
instead of manually modifying global state" (8 sites) — each is a bare
sys.path.insert(0, str(REPO / "scripts")) inside a test function, with
nothing to undo it once the test returns, so the path entry leaks into every
test that runs afterward in the same process:

  • tests/test_family.py:183,207,243
  • tests/test_scaffold_e2e.py:688,716,814,841,897

What would fix it. For S9073, split each composite assert X and Y into
two separate assert X / assert Y statements, keeping a diagnostic message
on each half (duplicated or split as makes sense) so a failure still says
what broke — without changing what is actually asserted. For S8997, add the
monkeypatch fixture parameter to each affected test function and replace
the manual sys.path.insert(0, ...) with monkeypatch.syspath_prepend(...),
which restores sys.path automatically at teardown instead of leaking it.

Out of scope: tests/test_naming_policy.py (owned by another lane in this
fan-out) and anything outside tests/.

Activity

  1. brettheap commented on Sep 11, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-11T20:22Z) CLAIMED — session 3b1ab8cf, on Brett Heap's word 'go, fan out on all of it'. Branch chore/tests-split-assertions-and-monkeypatch, worktree ~/projects/openRepoShape--tests-sonar-assertions on Eagle, from origin/main cd57c4b. Scope: split the 22 S9073 composite assertions and convert the 8 S8997 manual sys.path mutations to monkeypatch, across the 9 tests/ files SonarCloud named; tests/test_naming_policy.py excluded (owned by another lane).

  2. brettheap commented on Sep 11, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-11T20:2xZ) PULL REQUEST OPEN: #116 (head f18a65e).

  3. brettheap commented on Sep 11, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-11T20:38:58Z) MERGED — #116 → bbc6c86 (squash), on Brett Heap's word 'go, fan out on all of it, hold the doctor refactor'. tests/: the 22 SonarCloud S9073 composite assertions split into separate asserts with their messages kept, and the 8 S8997 manual sys.path mutations replaced by monkeypatch.syspath_prepend, across nine test files, nothing outside tests/; the now-unused import sys dropped in test_scaffold_e2e.py; Copilot 'Approval recommended' with 0 findings; suite 984 passed / 1 known machine-dependent flake / 1 skipped. Object complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions