# AssertionError: assert <unittest.mock.MagicMock name='mock.method' id='140234567890'> is not None

- **ID:** `python/pytest-assertion-rewriting-error`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试断言模拟对象不是 None，但返回了模拟对象而不是实际值，表明模拟对象配置不正确。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Configure the mock to return a specific value: `mock.method.return_value = 'real_value'`
   ```
2. **** (90% 成功率)
   ```
   Use autospec=True in patch to ensure the mock matches the real method's signature.
   ```

## 无效尝试

- **** — This may still return a mock if the attribute is not properly set up, leading to confusing behavior. (70% 失败率)
- **** — A mock object is truthy, so this assertion always passes, masking the real issue. (90% 失败率)
