Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def pytest_pyfunc_call(pyfuncitem):
testargs = {arg: funcargs[arg]
for arg in pyfuncitem._fixtureinfo.argnames}
event_loop.run_until_complete(
asyncio.async(pyfuncitem.obj(**testargs)))
asyncio.async(pyfuncitem.obj(**testargs), loop=event_loop))
return True


Expand Down
33 changes: 33 additions & 0 deletions tests/test_non_global_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import asyncio

import pytest


def setup_module(module):
asyncio.set_event_loop(None)


def teardown_module(module):
# restore the default policy
asyncio.set_event_loop_policy(None)


@pytest.fixture
def event_loop(request):
loop = asyncio.new_event_loop()
request.addfinalizer(loop.close)
return loop


@asyncio.coroutine
def example_coroutine():
return 42


@pytest.mark.asyncio
def test_asyncio_marker_with_non_global_loop(event_loop):
with pytest.raises(RuntimeError):
_ = asyncio.get_event_loop()

result = yield from example_coroutine()