python
runtime_error
ai_generated
partial
Failed: 警告摘要 ... PytestUnraisableExceptionWarning: 异常被忽略: <function ...>
Failed: Warnings summary ... PytestUnraisableExceptionWarning: Exception ignored in: <function ...>
ID: python/pytest-warnings-summary-failed
80%修复率
85%置信度
0证据数
2024-04-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
在垃圾回收期间发生了无法引发的异常,通常是由于文件或套接字未正确关闭。当设置了 -W error 或警告被配置为错误时,pytest 会将其视为失败。
English
An unraisable exception occurred during garbage collection, often due to a file or socket not being closed properly. pytest treats this as a failure when -W error is set or when the warning is configured as error.
解决方案
-
95% 成功率
Use context managers or explicit close in teardown: @pytest.fixture def resource(): r = open('file') yield r r.close() -
80% 成功率
In pytest.ini: [pytest] filterwarnings = ignore::pytest.PytestUnraisableExceptionWarning
无效尝试
常见但无效的做法:
-
70% 失败
This hides the symptom but the resource leak remains, potentially causing other issues.
-
80% 失败
Forcing collection may trigger the warning earlier but does not fix the leak.