python
config_error
ai_generated
true
Failed: tmpdir fixture 已弃用,请改用 tmp_path E pytest.PytestRemovedIn9Warning: tmpdir fixture 已弃用
Failed: The tmpdir fixture is deprecated, use tmp_path instead E pytest.PytestRemovedIn9Warning: The tmpdir fixture is deprecated
ID: python/pytest-tmpdir-deprecation-error
80%修复率
87%置信度
0证据数
2024-04-23首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 8.x | active | — | — | — |
根因分析
测试使用 `tmpdir`,在 pytest 8 中已被弃用,推荐使用 `tmp_path`。当 `filterwarnings = error` 时,弃用警告变为失败。
English
The test uses `tmpdir` which is deprecated in pytest 8 in favor of `tmp_path`. With `filterwarnings = error`, the deprecation becomes a failure.
解决方案
-
95% 成功率
Replace `tmpdir` with `tmp_path`: def test_file(tmp_path): p = tmp_path / 'data.txt' p.write_text('hi') assert p.read_text() == 'hi' -
80% 成功率
If you need py.path API, use `tmp_path` and `py.path.local(tmp_path)` explicitly.
无效尝试
常见但无效的做法:
-
60% 失败
Hides the warning but the API will be removed in pytest 9, causing future breakage.
-
55% 失败
Delays the migration but blocks other fixes and security updates.