diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index c6d2d7e4..bac9565d 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -58,9 +58,15 @@ def pytest_pyfunc_call(pyfuncitem): funcargs = pyfuncitem.funcargs testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames} + test_coroutine = pyfuncitem.obj(**testargs) + + if 'timeout' in pyfuncitem.keywords[marker_name].kwargs: + timeout = pyfuncitem.keywords[marker_name].kwargs['timeout'] + test_coroutine = asyncio.wait_for(test_coroutine, timeout=timeout) + try: event_loop.run_until_complete( - asyncio.async(pyfuncitem.obj(**testargs), loop=event_loop)) + asyncio.async(test_coroutine, loop=event_loop)) return True finally: if forbid_global_loop: diff --git a/tests/test_simple.py b/tests/test_simple.py index 1b305904..ee20fa27 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -58,6 +58,12 @@ def test_asyncio_process_pool_marker(event_loop): assert ret == 'ok' +@pytest.mark.xfail(raises=asyncio.TimeoutError) +@pytest.mark.asyncio(timeout=0.05) +def test_asyncio_marker_fail(): + yield from asyncio.sleep(0.1) + + @pytest.mark.asyncio def test_unused_port_fixture(unused_tcp_port, event_loop): """Test the unused TCP port fixture."""