python attribute_error ai_generated true

AttributeError: 'TempPathFactory' object has no attribute 'mktemp'

ID: python/pytest-tmpdir-factory-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2025-06-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.4.0 active

Root Cause

在非 pytest 环境中使用了 tmp_path_factory,或版本不支持该方法。

generic

中文

在非 pytest 环境中使用了 tmp_path_factory,或版本不支持该方法。

Workarounds

  1. 100% success
    在测试函数中直接使用 `tmp_path` 参数,pytest 自动提供。
  2. 85% success
    确保 pytest >= 7.0 并使用 `tmp_path_factory.mktemp('name')`。

Dead Ends

Common approaches that don't work:

  1. 50% fail

    绕过 pytest 的临时目录管理,可能冲突。

  2. 40% fail

    如果已是最新版本,无济于事。