Duplicate tests
duplicate_tests
Duplicate-tests rule — cluster likely-duplicate test functions.
Three clustering signals (S1/S2/S3) + six rescue anti-signals (P1-P6)
ported from the detect_duplicates.py prototype.
DuplicateTestsCheckResult
Bases: CheckResult
:class:CheckResult with cluster metadata.
metadata keys:
clusters— list of cluster payloads, each withcluster_hash, amemberslist of test entries, and an optionalacknowledgedflag (Truewhen the hash is present in[[tool.axm-audit.duplicate_tests.acknowledged]]). The cluster shape exposesmembersonly; the legacytestsalias was removed in axm-1728 — consumers readingcluster["tests"]get aKeyErrorby design.bucket_counts— CLUSTERED / AMBIGUOUS / UNIQUE test counts.stale_acknowledged— acknowledgement entries ({hash, reason}) whose hash no longer matches any vivant cluster. Informational only: does not affectpassed/score/severity.config_error— present whenpyproject.tomlis malformed or the[tool.axm-audit.duplicate_tests]schema is invalid. The audit falls back to "no acknowledgements" rather than crashing.
Source code in packages/axm-audit/src/axm_audit/core/rules/test_quality/duplicate_tests.py
DuplicateTestsRule
dataclass
Bases: ProjectRule
Cluster likely-duplicate test functions via structural signals.
Source code in packages/axm-audit/src/axm_audit/core/rules/test_quality/duplicate_tests.py
rule_id
property
Stable identifier for this rule.
check(project_path)
Cluster duplicate tests in project_path and return verdicts.
Source code in packages/axm-audit/src/axm_audit/core/rules/test_quality/duplicate_tests.py
collect_assert_call_sigs(node)
Return _call_sig set for every :class:ast.Call inside an assert.
Tests written as assert helper(args) == expected would otherwise have
an empty call_sig (the taint-propagation pass only follows assigns).
Including these calls lets S1/S2 group such tests by SUT.
Source code in packages/axm-audit/src/axm_audit/core/rules/test_quality/duplicate_tests.py
merge_clusters(clusters)
Union-find merge; ambiguous sub-clusters dominate the merged signal.
Source code in packages/axm-audit/src/axm_audit/core/rules/test_quality/duplicate_tests.py
p10_rescues(tests)
Locality rescue: demote when all pairs are far apart with no strong signal.
Returns True iff every pair in tests has line distance greater than
:data:_P10_LINE_DIST AND no pair carries a very strong direct signal
(:func:_pair_is_very_strong). Tests that match this pattern are almost
always coincidental matches the user does not want flagged firmly.
Source code in packages/axm-audit/src/axm_audit/core/rules/test_quality/duplicate_tests.py
render_clusters_text(clusters, stale_acknowledged=None)
Render top-N clusters (signal + ambiguous) as a compact bullet list.
When stale_acknowledged is provided, append one warning line per
stale entry of the form
⚠ stale acknowledged cluster: <hash> (<reason>). Stale warnings
are suffix-only and never affect passed / score / severity.