python
runtime_error
ai_generated
partial
Failed: Warnings summary ... PytestUnraisableExceptionWarning: Exception ignored in: <function ...>
ID: python/pytest-warnings-summary-failed
80%Fix Rate
85%Confidence
0Evidence
2024-04-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
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.
generic中文
在垃圾回收期间发生了无法引发的异常,通常是由于文件或套接字未正确关闭。当设置了 -W error 或警告被配置为错误时,pytest 会将其视为失败。
Workarounds
-
95% success
Use context managers or explicit close in teardown: @pytest.fixture def resource(): r = open('file') yield r r.close() -
80% success
In pytest.ini: [pytest] filterwarnings = ignore::pytest.PytestUnraisableExceptionWarning
Dead Ends
Common approaches that don't work:
-
70% fail
This hides the symptom but the resource leak remains, potentially causing other issues.
-
80% fail
Forcing collection may trigger the warning earlier but does not fix the leak.