@contextmanager
def freeze_time(t):
 _real_time = time.time
 time.time = (lambda : t)
 try:
  (yield)
 finally:
  time.time = _real_time

@ contextmanager def freeze_time ( t ) : _real_time = time . time time . time = ( lambda : t ) try : ( yield ) finally : time . time = _real_time
context manager to temporarily freeze time .