freezegun icon indicating copy to clipboard operation
freezegun copied to clipboard

freeze_time doesn't work with functools.partial

Open Dunedan opened this issue 7 years ago • 2 comments

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

Dunedan avatar Oct 23 '18 09:10 Dunedan

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.

spulec avatar Jul 09 '19 01:07 spulec