Skip to content

PY-TEST0002 · legacy_tmpdir_fixture_count

Count uses of pytest’s legacy tmpdir fixtures.

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

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.

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.

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.

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"