Monkey patch time.time () in python

I have an application where, for testing, I need to replace the time.time () call with a specific timestamp, I did this in the past using ruby

(code is available here: http://github.com/zemariamm/Back-to-Future/blob/master/back_to_future.rb )

However, I do not know how to do this using Python.

Any clues? Hooray, the Maria

+4
source share
1 answer

You can simply set time.time to point to your new time function, for example:

import time def my_time(): return 0.0 old_time = time.time time.time = my_time 
+14
source

Source: https://habr.com/ru/post/1304139/


All Articles