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

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

## 根因

测试断言 `mock.assert_called_once()`，但 mock 在断言前被重置（例如被 `mock.reset_mock()` 或某个 fixture 重置），或者被测代码 patch 了错误的目标。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Patch where the name is looked up and verify the patch target:

@patch('app.services.user.send_email')
def test_signup(mock_send):
    signup()
    mock_send.assert_called_once()
   ```
2. **** (90% 成功率)
   ```
   Remove any `reset_mock()` calls between the action and the assertion, or use `mock.call_count` to inspect at the exact point.
   ```

## 无效尝试

- **** — Still fails if the mock was never called; masks the real issue. (70% 失败率)
- **** — Repeating the assertion does not change the call count. (95% 失败率)
