# ImportError: 没有名为 'module_to_patch' 的模块

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

## 根因

`@unittest.mock.patch('module_to_patch.ClassName')` 装饰器尝试修补一个不存在或不可导入的模块。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Ensure the module path is correct: `@patch('my_package.module_to_patch.ClassName')`
   ```
2. **** (90% 成功率)
   ```
   Use patch.object() with the actual class: `@patch.object(MyClass, 'method_name')`
   ```

## 无效尝试

- **** — The module might be an internal part of the codebase that should be patched differently. (60% 失败率)
- **** — Decorators are evaluated at import time; try-except cannot catch import errors in this context. (90% 失败率)
