You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function can only be called from a coroutine or a callback.
Being able to run invocations in the event loop in a sync function is convenient, as we don't have 100% async codebase, and tests are mostly written in sync.
Do you see the use case here @seifertm? Is the advice to convert the usages to async and then asyncio.to_thread() to sync parts, instead?
The migration guide suggests converting such tests to async tests and use get_running_loop inside the async test. Following your example:
@pytest_asyncio.fixture()asyncdefsome_fixture():
# do some sync stuff etc...# then trigger async actions:event_loop=asyncio.get_running_loop()
event_loop.run_until_complete(...)
You could possibly even skip asyncio.get_running_loop() in favour of:
@pytest_asyncio.fixture()asyncdefsome_fixture():
# do some sync stuff etc...# then trigger async actions:await ...
@tuukkamustonen Do any of those approaches work for your code base?
https://pytest-asyncio.readthedocs.io/en/latest/reference/fixtures/index.html#event-loop suggests that it's fine to grab
event_loop
fixture in a non-async function.0.21+ migration guide in https://pytest-asyncio.readthedocs.io/en/latest/how-to-guides/migrate_from_0_21.html suggests to convert all sync functions requesting the
event_loop
fixture into async functions, and then acquire the loop viaasyncio.get_running_loop()
.Which one is it, and what is the rationale of not depending on the
event_loop
fixture directly?The text was updated successfully, but these errors were encountered: