Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
deprecate calling fixtures as functions #3661
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
I'd like to propose introducing a flag such as
GitMate.io thinks possibly related issues are #498 (Function scope fixture with failing finalizer called only once), #1805 (Fixture that calls getattr() on request.function throws an AttributeError: 'function' object has no attribute), #1875 (Cannot create two fixtures based on the same function), #2001 (Using fixture decorator as a function), and #2334 (Defining differently-scoped fixtures with single function messes up fixture scope).