Skip to content

"Task exception was never retrieved" warning with Skipped exception #123

Closed
@blueyed

Description

@blueyed

The Skipped exception used by pytest (e.g. pytest.importorskip) is derived from BaseException, and therefore is not caught by asyncio.events's _run:

Ref: https://github.com/pytest-dev/pytest/blob/865e84d206581f77640cfbc1516aff7a0d7316c6/src/_pytest/outcomes.py#L36

https://github.com/blueyed/cpython/blob/443fe5a52a3d6a101795380227ced38b4b5e0a8b/Lib/asyncio/events.py#L79-L94

This results in the following warning/error when using it in an async test:

Task exception was never retrieved
future: <Task finished coro=<test_database_sync_to_async() done, defined at …/Vcs/channels/tests/test_db.py:6> exception=could not import 'psycopg2xx'>
Traceback (most recent call last):
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/_pytest/runner.py", line 226, in from_call
    result = func()
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/_pytest/runner.py", line 198, in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 68, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 62, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/_pytest/runner.py", line 123, in pytest_runtest_call
    item.runtest()
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/_pytest/python.py", line 1464, in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 68, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 62, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "…/Vcs/pytest-asyncio/pytest_asyncio/plugin.py", line 158, in pytest_pyfunc_call
    pyfuncitem.obj(**testargs), loop=event_loop))
  File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
    self._run_once()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 1775, in _run_once
    handle._run()
  File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "…/Vcs/channels/tests/test_db.py", line 15, in test_database_sync_to_async
    pytest.importorskip("psycopg2xx")
  File "…/Vcs/channels/.venv/lib/python3.7/site-packages/_pytest/outcomes.py", line 172, in importorskip
    raise Skipped(reason, allow_module_level=True)
Skipped: could not import 'psycopg2xx'

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