This rule raises an issue when the plugin configuration variable is defined in a regular test file (any file other than the designated configuration file).
pytest_plugins in conftest.py loads before test collection, so plugins are available for early hooks such as
pytest_addoption. In test modules, plugins load only when that module is imported during collection, which can change behavior under
parallel CI.
Pytest deduplicates plugins by name, so declaring the same plugin in multiple test modules does not load it twice. The risk is late registration and collection-order dependence, not duplicate initialization.
This rule flags any pytest_plugins assignment outside conftest.py.
Misplaced plugin declarations make load order depend on collection sequence, so the same suite can pass locally and fail under parallel or sharded CI.
Move pytest_plugins from test modules to conftest.py in the same directory or a parent directory.
# test_something.py
pytest_plugins = ['pytest_cov', 'pytest_timeout'] # Noncompliant
def test_feature():
assert True
# conftest.py
pytest_plugins = ['pytest_cov', 'pytest_timeout']
# test_something.py
def test_feature():
assert True