Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time_to_freeze.today() returns wrong time and type if TZ is not 'UTC' in env vars #513

Open
sfreilich opened this issue Oct 6, 2023 · 2 comments

Comments

@sfreilich
Copy link

When I run the tests with the latest version of freezegun, I get:

self = <freezegun.tests.test_datetimes.TestUnitTestMethodDecorator testMethod=test_method_decorator_works_on_unittest_kwarg_frozen_time>
frozen_time = <freezegun.api.FrozenDateTimeFactory object at 0x7f8a7ab07f70>

    @freeze_time('2013-04-09', as_kwarg='frozen_time')
    def test_method_decorator_works_on_unittest_kwarg_frozen_time(self, frozen_time):
        self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today())
>       self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today())
E       AssertionError: FakeDate(2013, 4, 9) != datetime.datetime(2013, 4, 8, 17, 0)

This is strange fore two reasons. First, the returned value is not in the expected timezone, given that tz_offset defaults to 0. Second, it's surprising that test assertion passed, since while datetime.date.today() should return a datetime.date, frozen_time.time_to_freeze is a datetime so that .today() should be a datetime, and datetimes don't compare equal to dates.

Was some past version of dateutil.parser parsing "2013-04-09" as a datetime.date instead of a datetime.datetime when no timezone was specified?

@sfreilich
Copy link
Author

This seems to be fixed at head.

@sfreilich
Copy link
Author

Ah, wait, nevermind, that was with TZ=UTC. I'm still confused why the test expects datetime.date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant