prefer-pytest-fixture-contract
Expose existing abstract contracts from pytest fixtures and injected parameters.
Why
Concrete fixture exports and injected parameter annotations couple consumers to an implementation even when an existing ABC or Protocol supports the consumed operations.
Fix
Keep concrete construction in the fixture and annotate supplied instances and injected parameters with their existing ABC or Protocol. Retain a reviewed concrete annotation for implementation-specific behavior or stronger concrete guarantees.
Examples
import pytestfrom abc import ABC, abstractmethod
class Store(ABC): @abstractmethod def read(self) -> int: ...
class SqlStore(Store): def read(self) -> int: return 1
class Router: def __init__(self, store: Store) -> None: self.store = store
@pytest.fixturedef router(store: SqlStore) -> Router: return Router(store=store)import pytestfrom abc import ABC, abstractmethod
class Store(ABC): @abstractmethod def read(self) -> int: ...
class SqlStore(Store): def read(self) -> int: return 1
class Router: def __init__(self, store: Store) -> None: self.store = store
@pytest.fixturedef router(store: Store) -> Router: return Router(store=store)