Description
We often declare fixtures in the same module that uses them. I've seen people new to the codebase, especially ones who haven't been heavy pytest users before, often use the fixtures interchangeably as functions, i.e.
@pytest.fixture
def model():
...
def test_foo(model):
my_model = model
def test_bar():
my_model = model()
The fixtures are intentionally made callable, but I'd argue that in many codebases, the the dual use of a fixture in this way breeds confusion and can mislead a novice programmer. For example, if the fixture requires other fixtures, i.e.
@pytest.fixture(params=[1, 2])
def parent_model(request):
...
@pytest.fixture
def model(parent_model):
...
a novice programmer might conclude that they need to provide the parent_model
parameter to model()
, not knowing that they're supposed to leave it up to the fixture resolution (which could e.g. result in a parameterized fixture).
I'd like to propose introducing a flag such as strict_fixtures
to make fixtures fail fast (with a clear explanation) if they're called as functions.