# 类型错误：assertRaises() 参数 1 必须是异常类型或异常类型的元组

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

## 根因

将非异常对象（如字符串或函数）作为 assertRaises 的第一个参数传递。

## 版本兼容性

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

## 解决方案

1. **** (99% 成功率)
   ```
   with self.assertRaises(ValueError):
    function_that_raises()
   ```
2. **** (99% 成功率)
   ```
   with self.assertRaises((ValueError, TypeError)):
    function_that_raises()
   ```

## 无效尝试

- **** — assertRaises expects the exception class, not an instance. (90% 失败率)
- **** — Strings are not valid exception types. (95% 失败率)
