time-machine icon indicating copy to clipboard operation
time-machine copied to clipboard

Add support for time.monotonic

Open patrick91 opened this issue 4 years ago • 1 comments

Closes #103, still wip :)

TODO:

  • [ ] time.monotonic_ns()
  • [ ] time.clock_gettime() when called with time.CLOCK_MONOTONIC or time.CLOCK_MONOTONIC_RAW

patrick91 avatar Jan 22 '21 22:01 patrick91

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!

pganssle avatar May 03 '21 15:05 pganssle

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.

adamchainz avatar Aug 30 '22 23:08 adamchainz