# AssertionError: 预期 'send_email' 被调用一次。实际调用 0 次。

- **ID:** `python/pytest-mock-not-called`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

被 mock 的函数未被调用，因为被测代码使用了不同的引用（例如直接导入），或者测试逻辑没有到达调用点。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   If myapp/service.py has 'from myapp.utils import send_email', patch 'myapp.service.send_email'.
If it has 'import myapp.utils', patch 'myapp.utils.send_email'.
   ```
2. **** (90% 成功率)
   ```
   Add a print before the call in the source code, or use pdb to step through.
   ```

## 无效尝试

- **** — The patch must target where the function is looked up, not where it's defined. (85% 失败率)
- **** — May not work if the code uses a module-level import. (80% 失败率)
