# DeprecationWarning: 'pytest.warns(None)' 已弃用

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

## 根因

使用 `pytest.warns(None)` 断言无警告自 pytest 7 起已弃用；它现在会引发警告，可能被转换为错误。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   import warnings
with warnings.catch_warnings():
    warnings.simplefilter('error')
    my_function()
   ```
2. **** (85% 成功率)
   ```
   with pytest.warns(UserWarning):
    my_function()
   ```

## 无效尝试

- **** — Hides the deprecation but does not fix the test logic; may break in future pytest versions. (70% 失败率)
- **** — Does not integrate with pytest's warning capture and may miss warnings from other threads. (60% 失败率)
