Skip to content

-W not working for warnings emitted from finalizer context #8021

Closed
@belm0

Description

@belm0

I'd like pytest to fail on "coroutine never awaited" RuntimeWarning. But something about these warnings cause pytest not to behave as expected: a matching -W spec actually causes the warning to be completely ignored.

I suspect it's because these warnings are issued on shutdown of the interpreter, after the pytest harness has exited.

def test_foo():
    async def bar():
        assert False

    bar()
$ pytest foo.py
====================================== test session starts ======================================
platform darwin -- Python 3.7.7, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
collected 1 item

foo.py .                                                                                  [100%]

======================================= warnings summary ========================================
foo.py::test_foo
foo.py:5: RuntimeWarning: coroutine 'test_foo.<locals>.bar' was never awaited
    bar()

-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================= 1 passed, 1 warning in 0.02s ==================================
$ pytest -Werror foo.py
====================================== test session starts ======================================
platform darwin -- Python 3.7.7, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
collected 1 item

foo.py .                                                                                  [100%]

======================================= 1 passed in 0.04s =======================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions