diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 24450bf7..39b9c698 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -140,9 +140,16 @@ def wrap_in_sync(func): def inner(**kwargs): coro = func(**kwargs) if coro is not None: - future = asyncio.ensure_future(coro) - asyncio.get_event_loop().run_until_complete(future) - + task = asyncio.ensure_future(coro) + try: + asyncio.get_event_loop().run_until_complete(task) + except BaseException: + # run_until_complete doesn't get the result from exceptions + # that are not subclasses of `Exception`. Consume all + # exceptions to prevent asyncio's warning from logging. + if task.done() and not task.cancelled(): + task.exception() + raise return inner diff --git a/tests/test_simple.py b/tests/test_simple.py index f9e3992f..1627139d 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -134,3 +134,8 @@ async def test_asyncio_marker_without_loop(self, remove_loop): """Test the asyncio pytest marker in a Test class.""" ret = await async_coro() assert ret == 'ok' + + +@pytest.mark.asyncio +async def test_no_warning_on_skip(): + pytest.skip("Test a skip error inside asyncio")