PY-TEST0002 · legacy_tmpdir_fixture_count
Count uses of pytest’s legacy tmpdir fixtures.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Inspect test modules and conftest.py files for injected parameters named tmpdir or
tmpdir_factory. Also count those names when supplied to request.getfixturevalue or
pytest.mark.usefixtures. The modern tmp_path and tmp_path_factory fixtures return
standard-library pathlib.Path values and are the preferred default.
Evidence
Section titled “Evidence”Each finding locates one fixture parameter or one dynamic fixture request and identifies the
legacy fixture name. Ordinary local variables called tmpdir are not fixture evidence. The
value is the number of legacy fixture uses across every collected test.
Exceptions
Section titled “Exceptions”A test that depends on py.path.local behavior can exclude its path or retain the finding with
an explicit project policy. The rule does not auto-fix because py.path.local methods and
pathlib.Path methods are not mechanically equivalent. Ruff has no pytest-style rule that
migrates these fixtures.
Examples
Section titled “Examples”def test_report(tmpdir): report = tmpdir.join("report.json") assert report.ext == ".json"def test_report(tmp_path): report = tmp_path / "report.json" assert report.suffix == ".json"References
Section titled “References”- Cites “pytest documentation”, temporary directory. Open reference
- Cites “The Python Standard Library”, pathlib. Open reference