# TypeError: 'MagicMock' 对象不可调用

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

## 根因

在需要可调用对象的地方使用了 MagicMock 实例，但该 mock 未配置为可调用，或者错误地访问了 mock 的 return_value。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   mock_func = MagicMock()
mock_func.return_value = 42
assert mock_func() == 42
   ```
2. **** (92% 成功率)
   ```
   mock_func = MagicMock()
mock_func.side_effect = lambda x: x * 2
assert mock_func(5) == 10
   ```

## 无效尝试

- **** — Mock is also not callable by default. The issue is configuration, not the mock class. (85% 失败率)
- **** — If the mock is not callable, adding parentheses will still raise TypeError. The mock must be configured as callable. (90% 失败率)
