# AssertionError: 未找到期望的调用。
期望: fetch('https://api.example.com')
  实际: fetch()

- **ID:** `python/unittest-mock-magicmock-assertion`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

assert_called_with 比较精确的位置参数和关键字参数。实际调用传入了不同的参数（例如 URL 对象而非字符串），或者 mock 在调用和断言之间被重置/重新配置。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   mock_fetch.assert_called_once()
args, kwargs = mock_fetch.call_args
assert str(args[0]) == 'https://api.example.com'
   ```
2. **** (82% 成功率)
   ```
   from unittest.mock import call, ANY
mock_fetch.assert_called_with(ANY)
assert mock_fetch.call_args.args[0].__str__().endswith('/api.example.com')
   ```

## 无效尝试

- **** — Only checks call count, not arguments; the bug (wrong URL) goes undetected. (80% 失败率)
- **** — matching.ANY makes the assertion always pass and hides the real argument mismatch. (85% 失败率)
