Files
siftlode/backend/tests/test_override_dep_convention.py
T
peter 8759b5860d test(be): every dependency override goes through override_dep
22 test files set `app.dependency_overrides[...]` by hand and tore down with a blanket `.clear()`
in a `finally`, which wipes every override rather than the test's own and stops fixtures composing.
They now take the `override_dep` fixture (helpers get it passed in), whose teardown restores each
key's prior value; no clear() carried meaning between two phases of a test. A convention test fails
any test file that writes `dependency_overrides` directly.
2026-09-19 17:26:07 +02:00

24 lines
1.1 KiB
Python

"""Dependency overrides go through `conftest.override_dep`, never `app.dependency_overrides` directly.
The hand-rolled shape — assign, then `app.dependency_overrides.clear()` in a `finally` — wipes EVERY
override, not the ones the test set, so it stops fixtures composing: one test's teardown silently
clobbers an override another fixture installed. `override_dep` restores each key's prior value
instead. 22 files had drifted to the hand-rolled shape (it was the house norm at ~20 files to 3), and
the sweep that converted them is only as good as the check that keeps it converted — this one.
"""
from pathlib import Path
TESTS = Path(__file__).parent
def test_no_test_writes_dependency_overrides_directly():
offenders = [
f"{p.name}:{n}"
for p in sorted(TESTS.rglob("*.py"))
if p.name not in {"conftest.py", Path(__file__).name}
for n, line in enumerate(p.read_text(encoding="utf-8").splitlines(), 1)
if "dependency_overrides" in line
]
assert offenders == [], "use the override_dep fixture: " + ", ".join(offenders)