python
attribute_error
ai_generated
true
AttributeError: 'TempPathFactory' object has no attribute 'mktemp'
ID: python/pytest-tmpdir-factory-error
80%Fix Rate
83%Confidence
0Evidence
2025-06-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
Root Cause
在非 pytest 环境中使用了 tmp_path_factory,或版本不支持该方法。
generic中文
在非 pytest 环境中使用了 tmp_path_factory,或版本不支持该方法。
Workarounds
-
100% success
在测试函数中直接使用 `tmp_path` 参数,pytest 自动提供。
-
85% success
确保 pytest >= 7.0 并使用 `tmp_path_factory.mktemp('name')`。
Dead Ends
Common approaches that don't work:
-
50% fail
绕过 pytest 的临时目录管理,可能冲突。
-
40% fail
如果已是最新版本,无济于事。