# 属性错误：'TempPathFactory' 对象没有属性 'mktemp'

- **ID:** `python/pytest-tmpdir-factory-error`
- **领域:** python
- **类别:** attribute_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.4.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — 绕过 pytest 的临时目录管理，可能冲突。 (50% 失败率)
- **** — 如果已是最新版本，无济于事。 (40% 失败率)
