Skip to content

fakes-in-shared-location

Review named top-level test doubles for shared-support ownership unless they are intentionally scenario-local.

Why

Reusable doubles hidden in an individual test module are difficult to discover and are often recreated. A per-file warning cannot prove cross-module reuse, so scenario-local doubles may remain with an exact rationale.

Fix

Move a reusable double to a testing, fakes, stubs, mocks, doubles, helpers, support, or test_utils module. Keep a deliberately local double near its scenario with an exact SARJ428 suppression and rationale.

Examples

Before — flagged A test module privately defines a named fake
tests/test_checkout.py
class FakePaymentGateway:
async def charge(self, amount: int) -> None:
pass
After — preferred A nested double is visibly coupled to one scenario
tests/test_checkout.py
def test_decline_retries_once():
class FakePaymentGateway:
async def charge(self, amount: int) -> None:
raise Declined()
assert retries(FakePaymentGateway()) == 1