freezegun
freezegun copied to clipboard
Aware Datetime Support
Feature request I suppose, but also looking for guidance. Consider this snippet below where the first test is failing.
I would have expected freezegun to interpret the timezone stored in the datetime object and apply this as a 'tz_offset'. This is not the case.
If it would be acceptable, I'd happily update the documentation with a pull request that this is not intended behaviour, and users should provide the tz_offset kwarg to achieve this. Alternatively, could this feature be added?
I am using pytest:
import pytz
import datetime as dt
TZ = pytz.timezone("Australia/Brisbane")
DT = dt.datetime(2019, 12, 25)
class TestFreezeGun:
@freezegun.freeze_time(TZ.localize(dt.datetime(2019, 12, 25)))
def test_freezegun_no_offset_TEST_FAILS(self):
assert TZ.localize(dt.datetime.now()) == TZ.localize(dt.datetime(2019, 12, 25)) # fails
@freezegun.freeze_time(TZ.localize(dt.datetime(2019, 12, 25)), tz_offset=10) # Australia/Brisbane is +10
def test_freezegun_with_offset(self):
assert TZ.localize(dt.datetime.now()) == TZ.localize(dt.datetime(2019, 12, 25))