freezegun
freezegun copied to clipboard
freeze_time doesn't work with functools.partial
When using functools.partial() to construct variants of functions to build datetime-objects, freeze_time doesn't work, as shown in the following example:
from datetime import datetime
from functools import partial
from dateutil.tz import tzutc
from freezegun import freeze_time
utcnow = partial(datetime.now, tzutc())
with freeze_time(datetime(2000, 1, 1, 1, 1, 1, 1, tzutc())):
print(datetime.now(tzutc()))
print(utcnow())
> 2000-01-01 01:01:01.000001+00:00
> 2018-10-23 09:42:51.229630+00:00
I think this is going to be hard for us to fix since partial already has a reference to datetime.now before freezegun gets a chance to run. I'm open to ideas though.