Skip to content

Commit

Permalink
Fix issue pytest-dev#112: 'Dynamically calling a fixture causes a run…
Browse files Browse the repository at this point in the history
…time error' by failing over to a ThreadPoolExecutor in cases where the expected event loop is already running. Notably this happens when calling 'request.getfixturevalue(argname)' because it dynamically calls a fixture that needs to be setup on an event loop that's already running pytest async tests
  • Loading branch information
ykuzma1 committed Apr 20, 2019
1 parent 813423d commit e2dbfba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""pytest-asyncio implementation."""
import asyncio
import concurrent.futures
import contextlib
import functools
import inspect
Expand Down Expand Up @@ -94,7 +95,10 @@ async def async_finalizer():

request.addfinalizer(finalizer)

return loop.run_until_complete(setup())
pool = concurrent.futures.ThreadPoolExecutor(1)
loop = asyncio.new_event_loop()
pool.submit(asyncio.set_event_loop, loop).result()
return pool.submit(loop.run_until_complete, setup()).result()

fixturedef.func = wrapper

Expand Down

0 comments on commit e2dbfba

Please sign in to comment.