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

Support running tests with a timeout. #34

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down