Replies: 2 comments
-
Just as a note (to help others that stumble upon this) there is a simple workaround. Install nest_asyncio and then put this into the root
|
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, your question is why pytest-asyncio cannot reuse an already running loop. That's a fair point to make. When writing unit tests, it can be a good idea to test a unit in isolation. In order to exclude any potential side-effects, pytest-asyncio tries to run the test in a fresh event loop. By design, the event loops in asyncio are limited to one per thread. The loop schedules all the coroutines and other awaitables in a thread. In order to do so, it monitors things like network sockets and forwards data to the corresponding coroutine whenever new data is available. This is why loops cannot be easily nested. There are some ways around it, e.g. nest_asyncio or aioloop-proxy, but none of them are currently integrated into pytest-asyncio, You can reuse an event loop over multiple tests by reimplementing the Does this explanation help? |
Beta Was this translation helpful? Give feedback.
-
When I run async tests using
pytest-asyncio
after integration tests usingplaywright-pytest
(only using playwright.sync_api calls), then those tests fail with the error already described in #359 . I don't know much about the internals ofpytest-asyncio
, but wouldn't it be possible to reuse the event loop when one is already running (and only try to start a new one when not)?Beta Was this translation helpful? Give feedback.
All reactions