python runtime_error ai_generated partial

Failed: Warnings summary ... PytestUnraisableExceptionWarning: Exception ignored in: <function ...>

ID: python/pytest-warnings-summary-failed

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-04-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

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

Dead Ends

Common approaches that don't work:

  1. 70% fail

    This hides the symptom but the resource leak remains, potentially causing other issues.

  2. 80% fail

    Forcing collection may trigger the warning earlier but does not fix the leak.