time-machine
time-machine copied to clipboard
Add support for time.monotonic
Closes #103, still wip :)
TODO:
- [ ] time.monotonic_ns()
- [ ] time.clock_gettime() when called with time.CLOCK_MONOTONIC or time.CLOCK_MONOTONIC_RAW
Since I came here to possibly make a similar PR, I'd like to humbly suggest adding support for time.perf_counter and time.perf_counter_ns in this as well. On most platforms, time.perf_counter is equivalent to time.monotonic, so there's a good chance they can share an implementation (which is what I did in my PR to freezegun).
DISCLAIMER: I am not associated with this project and I do not want to impose on your good will by requesting additional features — please ignore me if it adds any hardship to your PR!
This has sat around for a while, and I've not seen any other requests for support. I think adding monotonic support probably isn't worth it, at this time. Using mock.patch should be sufficient for most use cases, e.g.
In [8]: with mock.patch.object(time, 'monotonic', side_effect=[123, 234]):
...: print(time.monotonic())
...: print(time.monotonic())
...:
123
234
Thanks for the suggestion though @patrick91.