I have my_module.py
that I want to test.
In the module top level code, I have:
import asyncio
loop = asyncio.get_event_loop()
# code...
test1.py:
import mymodule
@pytest.mark.asyncio
def test_mymodule(event_loop):
await mymodule.func()
The problem is that the test freezes, since the event_loop set by pytest-asyncio
and mymodule.py
event loop are not the same.
This can be fixed by moving import mymodule
to inside the test function, but I prefer not to do so.
Is there a way for pytest to patch the default event loop before the test code is imported and executed?