PY-TEST0005 · pytest_import_isolation
Classify pytest import isolation from the effective import mode.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Read import_mode or --import-mode from the first pytest configuration selected by pytest.
importlib is isolated because it does not modify sys.path. append and the default
prepend modes are separate categories because both mutate the import path with different
precedence. Unknown values are invalid. This project-level check does not overlap Ruff’s
per-statement import rules.
Evidence
Section titled “Evidence”Non-isolated and invalid categories retain the effective configuration file and exact mode in
a finding. Absence is recorded as prepend, which is pytest’s documented default.
Exceptions
Section titled “Exceptions”Tests that intentionally import sibling test modules can accept a path-mutating category.
Pytest notes that importlib prevents test modules from importing one another unless test
utilities are moved into an importable application package.
Examples
Section titled “Examples”[tool.pytest.ini_options]addopts = "--import-mode=prepend"[tool.pytest]import_mode = "importlib"References
Section titled “References”- Cites “pytest documentation”, good integration practices. Open reference
- Cites “pytest documentation”, import mechanisms. Open reference
- Cites “pytest documentation”, configuration precedence. Open reference