pytest-asyncio
pytest-asyncio copied to clipboard
[Feature Request] Event-Loop fixture that does not automatically advance time
It would be ideal to add an additional clock_event_loop fixture with a custom AbstractEventLoop. Instead, this one would only advance time explicitly similar to the twisted.internet.task.Clock useful for testing twisted reactors. This would allow for tests to advance time and test time-based features to verify that they are correctly running when expected without having to wait for time to progress. If there is a different way to achieve this goal, I would appreciate the advice if I missed something.
https://github.com/pytest-dev/pytest-asyncio/issues/83 seems similar to what you want
Thanks @albertodonato , I've been working on this for a bit now and #110 is the most recent set of commits to achieve this behavior in case you are interested.
Looking at your fixture in #83 is very interesting. #110 (and the original #96) takes a different approach, changing the loop class to give all event_loop's the advance_time coroutine, but having it as a stand alone fixture could be a good alternative solution. You would probably want to remove any calls to private loop functions though (e.g. loop._ready)
Along with the inspiration from Twisted, consider Trio as well. https://pytest-trio.readthedocs.io/en/stable/reference.html#autojump_clock Advancing time automatically even faster than the wall clock is very useful as well.