pytest-fixture-autouse (RUF076)
Preview (since 0.15.17) · Related issues · View source
This rule is unstable and in preview. The --preview flag is required for use.
What it does
Checks for pytest fixtures that set the parameter autouse=True in the decorator constructor.
Why is this bad?
Autouse fixtures are run implicitly, which can make test behavior hard to
reason about in general, but especially when defined in conftest.py files.
Autouse fixtures in conftest.py files are automatically run for
all tests in the directory structure, which can introduce hidden side effects,
make test suites slower, and make debugging difficult.
Instead, prefer to explicitly request/inject fixtures in tests, test classes, or other fixtures that need them by declaring them in the function parameters.
Example
Use instead:
Note
This is a pedantic rule that restricts a valid pytest pattern. If you choose to
enable it, you may want to ignore it outside of conftest.py files,
as autouse fixtures are most problematic when defined globally.
You can do this by configuring lint.per-file-ignores: