Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
blueyed opened this issue May 7, 2019 · 1 comment · Fixed by #126
Closed

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

blueyed opened this issue May 7, 2019 · 1 comment · Fixed by #126

Comments

@blueyed
Copy link
Contributor

blueyed commented May 7, 2019

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'
@jcrist
Copy link
Contributor

jcrist commented Jul 2, 2019

Should be fixed by #126.

blueyed added a commit that referenced this issue Jul 16, 2019
Asyncio doesn't get the results of tasks that fail with exceptions that
don't subclass `Exception` (like pytest's `Skipped`) in
`run_until_complete`. This leads to asyncio logging noisily warnings when
pytest's skip functionality is mixed with this plugin.

This fixes this error, and adds a test.

Fixes #123.

Co-Authored-By: Daniel Hahler <[email protected]>
Co-Authored-By: Andrew Svetlov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants