Anti mirror
anti_mirror
Anti-mirror rule — integration/e2e tests must not be named after source modules.
Industry convention (pyOpenSci, Real Python, the Pyramid testing literature):
tests/integration/ and tests/e2e/ test files describe a scenario or a
user action, not a source module. A tests/integration/test_foo.py whose
basename collides with src/<pkg>/.../foo.py is almost always a misplaced
unit test — it duplicates the unit-mirror surface (MirrorRule) and obscures
the behaviour the integration suite is supposed to verify.
This rule walks tests/integration/**/test_*.py and tests/e2e/**/test_*.py
and flags every test file whose test_<name>.py shadows a source module
basename. tests/unit/ is never walked here — that's MirrorRule's job.
AntiMirrorRule
dataclass
Bases: ProjectRule
Flag integration/e2e tests named after source modules.
Integration and e2e tests are scenario-named by convention. A
tests/integration/test_foo.py that mirrors src/<pkg>/foo.py is
almost always a misplaced unit test — promote it to tests/unit/ or
rename to describe the verified scenario.
Sources matched by [tool.axm-audit.mirror].exempt_paths are excluded:
a CLI-wrapper module like commands/data.py exempted by AXM-1666 is
legitimately covered by tests/integration/test_data.py.
Scoring: max(0, 100 - len(violations) * 15); passed = score >= 90.
Source code in packages/axm-audit/src/axm_audit/core/rules/practices/anti_mirror.py
| Python | |
|---|---|
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
rule_id
property
Unique identifier for this rule.
check(project_path)
Walk integration/e2e and flag tests named after source modules.