How to set custom event loop for a single test? #1294
-
|
Hello, my case is that I have a event loop that mocks the time pass and it works on async tests only. Some of my code uses internally normal time.sleep (theads) so using this mock loop makes it hangs. That is why I don't want to set up default/global event loop policy, just to use it for some tests, from time to time. asyncio.set_event_loop makes it throw warnings, so it can cause side effects I guess. A workaround would be to put some of my tests in a test class and put a event_loop_policy to be overriden in there. Any other options? class TestWithCustomEventLoop: # artificial, dummy scope
def event_loop_policy(self):
return SimulatedTimeEventLoopPolicy()
async def test_with_custom_event_loop(self):
print(asyncio.get_event_loop()) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Currently, there's no other option to override the event loop policy. There have been some attempts to replace it (#1032, #1101), but nothing final yet. If you want to override the policy only for some test, your current approach is the way to go. |
Beta Was this translation helpful? Give feedback.
Currently, there's no other option to override the event loop policy. There have been some attempts to replace it (#1032, #1101), but nothing final yet.
If you want to override the policy only for some test, your current approach is the way to go.