# 失败：未引发 <class 'ValueError'>

- **ID:** `python/pytest-raises-no-exception`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest.raises() 内部的代码块未引发预期的异常，表明存在错误或不正确的测试假设。

## 版本兼容性

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

## 解决方案

1. **Review the code to ensure it raises the expected exception under the given conditions.** (90% 成功率)
   ```
   Add print statements or debug to verify the code path.
   ```
2. **Use pytest.raises with match parameter to check exception message.** (85% 成功率)
   ```
   with pytest.raises(ValueError, match='invalid value'): code_that_should_raise()
   ```

## 无效尝试

- **Adding a try-except block inside pytest.raises to catch the exception** — pytest.raises already handles exception catching; extra try-except may swallow the exception. (70% 失败率)
- **Changing the expected exception to a broader type** — This may mask the real issue where no exception is raised at all. (60% 失败率)
