# 类型错误：使用 mock.assert_called_with 时 'NoneType' 对象不可调用

- **ID:** `python/unittest-mock-assert-called-with-typeerror`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

模拟对象未正确配置，或在断言之前被非可调用值（例如 None）替换。

## 版本兼容性

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

## 解决方案

1. **Ensure the mock is created with 'autospec=True' to maintain callable signature.** (85% 成功率)
   ```
   mock = unittest.mock.MagicMock(autospec=True); mock.assert_called_with(args)
   ```
2. **Verify the mock is not overwritten by using patch with return_value set explicitly.** (80% 成功率)
   ```
   with unittest.mock.patch('module.function', return_value=mock_callable): ...
   ```

## 无效尝试

- **Adding more mock assertions without checking mock creation** — The core issue is the mock object itself; additional assertions will fail similarly. (90% 失败率)
- **Using patch decorator incorrectly and assuming mock is automatically callable** — If patch replaces the object with a non-callable, the mock will not be callable. (75% 失败率)
