# Failed: 警告摘要
...
PytestUnraisableExceptionWarning: 异常被忽略: <function ...>

- **ID:** `python/pytest-warnings-summary-failed`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在垃圾回收期间发生了无法引发的异常，通常是由于文件或套接字未正确关闭。当设置了 -W error 或警告被配置为错误时，pytest 会将其视为失败。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Use context managers or explicit close in teardown:
@pytest.fixture
def resource():
    r = open('file')
    yield r
    r.close()
   ```
2. **** (80% 成功率)
   ```
   In pytest.ini:
[pytest]
filterwarnings =
    ignore::pytest.PytestUnraisableExceptionWarning
   ```

## 无效尝试

- **** — This hides the symptom but the resource leak remains, potentially causing other issues. (70% 失败率)
- **** — Forcing collection may trigger the warning earlier but does not fix the leak. (80% 失败率)
