Skip to content

Asyncio warnings when exiting a test with a next command and filterwarnings configured to error #295

Description

@vxgmichel

This can be easily reproduced with the following pyproject.toml configuration:

[project]
name = "test-ipdb"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11.11"
dependencies = [
    "ipdb>=0.13.13",
    "pytest>=9.1.1",
]


[tool.pytest.ini_options]
addopts = "--pdbcls=IPython.terminal.debugger:TerminalPdb"
filterwarnings = "error"

And the following trivial test:

def test_rep():
    assert False

Then run pytest with python 3.13 and the --pdb option:

$ uv run --python=3.13 pytest --pdb

Once in the ipdb prompt, use the (n)ext command:

ipdb> next

The following exception group is then printed on screen:

  + Exception Group Traceback (most recent call last):
  |   File "/home/vinmic/repos/test-ipdb/.venv/bin/pytest", line 10, in <module>
  |     sys.exit(_console_main())
  |              ~~~~~~~~~~~~~^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/config/__init__.py", line 253, in _console_main
  |     code = _main(prog=_get_prog_name(sys.argv))
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/config/__init__.py", line 229, in _main
  |     ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
  |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__
  |     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  |            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexec
  |     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  |            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicall
  |     raise exception
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicall
  |     res = hook_impl.function(*args)
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/main.py", line 377, in pytest_cmdline_main
  |     return wrap_session(config, _main)
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/main.py", line 372, in wrap_session
  |     config._ensure_unconfigure()
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1212, in _ensure_unconfigure
  |     self.hook.pytest_unconfigure(config=self)
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__
  |     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  |            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexec
  |     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  |            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicall
  |     raise exception
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicall
  |     res = hook_impl.function(*args)
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/unraisableexception.py", line 173, in pytest_unconfigure
  |     collect_unraisable(config)
  |     ~~~~~~~~~~~~~~~~~~^^^^^^^^
  |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/unraisableexception.py", line 81, in collect_unraisable
  |     raise ExceptionGroup("multiple unraisable exception warnings", errors)
  | ExceptionGroup: multiple unraisable exception warnings (3 sub-exceptions)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/unraisableexception.py", line 33, in gc_collect_harder
    |     gc.collect()
    |     ~~~~~~~~~~^^
    | ResourceWarning: unclosed <socket.socket fd=16, family=1, type=1, proto=0>
    |
    | The above exception was the direct cause of the following exception:
    |
    | Traceback (most recent call last):
    |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
    |     warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
    |     ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=16, family=1, type=1, proto=0>
    | Enable tracemalloc to get traceback where the object was allocated.
    | See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
    +---------------- 2 ----------------
    | Traceback (most recent call last):
    |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/unraisableexception.py", line 33, in gc_collect_harder
    |     gc.collect()
    |     ~~~~~~~~~~^^
    | ResourceWarning: unclosed <socket.socket fd=15, family=1, type=1, proto=0>
    |
    | The above exception was the direct cause of the following exception:
    |
    | Traceback (most recent call last):
    |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
    |     warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
    |     ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=15, family=1, type=1, proto=0>
    | Enable tracemalloc to get traceback where the object was allocated.
    | See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
    +---------------- 3 ----------------
    | Traceback (most recent call last):
    |   File "/home/vinmic/.local/share/uv/python/cpython-3.13.13-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 764, in __del__
    |     _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self)
    |     ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
    |
    | The above exception was the direct cause of the following exception:
    |
    | Traceback (most recent call last):
    |   File "/home/vinmic/repos/test-ipdb/.venv/lib/python3.13/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
    |     warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
    |     ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | pytest.PytestUnraisableExceptionWarning: Exception ignored in: <function BaseEventLoop.__del__ at 0x72c201cd98a0>
    | Enable tracemalloc to get traceback where the object was allocated.
    | See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
    +------------------------------------

Note that it fails before the prompt when using python 3.14 due to the following warning:

DeprecationWarning: The frame locals reference is no longer cached. Use 'curframe.f_locals' instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions