# 属性错误：<class 'module'> 没有属性 'some_function'

- **ID:** `python/unittest-mock-patch-attribute-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用 @patch 或 patch.object 时，目标路径不正确（例如，修补不存在的属性）会在应用模拟时导致 AttributeError。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Verify the exact attribute path: e.g., patch('mymodule.submodule.some_function') and ensure the attribute exists in the module.
   ```
2. **** (85% 成功率)
   ```
   Use patch.object with the actual object: patch.object(mymodule, 'some_function') after importing the module.
   ```

## 无效尝试

- **** — Changing the patch target to a different module without verifying the attribute exists may still fail if the attribute is imported incorrectly. (50% 失败率)
- **** — Using patch.object with a class that has the attribute but misspelling the attribute name leads to a similar error. (60% 失败率)
