# 属性错误：模块 'module_name' 没有属性 'function_name'

- **ID:** `python/unittest-mock-patch-wrong-target`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Mock patch 目标错误；修补了模块路径，而不是函数被使用的位置。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   @patch('module_where_used.function_name')
def test_something(mock_func):
    ...
   ```
2. **** (90% 成功率)
   ```
   @patch('module_name.function_name', create=True)
   ```

## 无效尝试

- **** — If the function is imported into another module, patching the original module doesn't affect the imported reference. (80% 失败率)
- **** — patch.object requires an existing attribute; if the attribute doesn't exist, it raises AttributeError. (70% 失败率)
