python config_error ai_generated true

Failed: The tmpdir fixture is deprecated, use tmp_path instead E pytest.PytestRemovedIn9Warning: The tmpdir fixture is deprecated

ID: python/pytest-tmpdir-deprecation-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-04-23First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8.x active — — —

Root Cause

The test uses `tmpdir` which is deprecated in pytest 8 in favor of `tmp_path`. With `filterwarnings = error`, the deprecation becomes a failure.

generic

中文

测试使用 `tmpdir`,在 pytest 8 中已被弃用,推荐使用 `tmp_path`。当 `filterwarnings = error` 时,弃用警告变为失败。

Workarounds

  1. 95% success
    Replace `tmpdir` with `tmp_path`:
    def test_file(tmp_path):
        p = tmp_path / 'data.txt'
        p.write_text('hi')
        assert p.read_text() == 'hi'
  2. 80% success
    If you need py.path API, use `tmp_path` and `py.path.local(tmp_path)` explicitly.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Hides the warning but the API will be removed in pytest 9, causing future breakage.

  2. 55% fail

    Delays the migration but blocks other fixes and security updates.