Skip to content

PY-TEST0001 · conftest_import

Detect an explicit import of a pytest conftest module.

This is a deterministic rule for python. Read its implementation.

Inspect Python import statements for import conftest, from conftest import fixture, package-qualified imports such as from tests.conftest import client, and relative forms such as from . import conftest. The expected default is zero because pytest discovers fixtures and local plugins from conftest.py according to directory scope.

Each finding identifies the complete import statement and every conftest module it names. A statement is counted once even when it binds several names from the same module.

allowed_modules can exempt an exact, uniquely packaged compatibility module when an external integration requires a normal import. Pytest discovery remains preferred. Imports from ordinary fixture plugin modules are accepted and are the supported way to share fixtures without broadening a conftest boundary. Ruff’s pytest rules do not own conftest imports.

from tests.conftest import authenticated_client
def test_account(authenticated_client):
assert authenticated_client.get("/account").status_code == 200
def test_account(authenticated_client):
assert authenticated_client.get("/account").status_code == 200
  • Cites “pytest documentation”, writing plugins and conftest.py plugins. Open reference
  • Cites “pytest documentation”, fixture availability. Open reference