# TypeError: assertRaises() 缺少 1 个必需的位置参数: 'callable'

- **ID:** `python/unittest-testcase-assertraises-no-context`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试调用 `self.assertRaises(SomeError)` 时未提供可调用对象，也未作为上下文管理器使用。assertRaises 需要第二个参数为可调用对象，或使用 `with self.assertRaises(SomeError):` 语法。

## 版本兼容性

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

## 解决方案

1. **** (97% 成功率)
   ```
   Use the context manager form:

with self.assertRaises(ValueError):
    parse_bad_input()
   ```
2. **** (95% 成功率)
   ```
   Or pass the callable as the second argument:

self.assertRaises(ValueError, parse_bad_input)
   ```

## 无效尝试

- **** — assertRaises expects an exception class or tuple of classes; an instance raises TypeError about expected exceptions. (85% 失败率)
- **** — Loses the assertRaises semantics and can silently pass if the wrong exception type is raised. (60% 失败率)
