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

tz_offset doesn't work well with django timezone #291

Open
qqpann opened this issue Mar 12, 2019 · 2 comments
Open

tz_offset doesn't work well with django timezone #291

qqpann opened this issue Mar 12, 2019 · 2 comments

Comments

@qqpann
Copy link

qqpann commented Mar 12, 2019

Python 3.7
freezegun 0.3.11
Django 2.1

tz_offset is not reflected on django's timezone correctly.

import datetime
from django.test import TestCase
from django.utils import timezone
from freezegun import freeze_time

class SomeTests(TestCase):
    @freeze_time('2019-04-01 00:00:00', tz_offset=9)
    def test_all_published_default(self):
        print(timezone.now())
        print(datetime.datetime.now())
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.....2019-04-01 00:00:00+00:00
2019-04-01 09:00:00
.......
----------------------------------------------------------------------
Ran 12 tests in 0.710s

OK
Destroying test database for alias 'default'...
@spulec
Copy link
Owner

spulec commented Jul 9, 2019

Can you check if you have settings.USE_TZ as True (or don't have it set and True is the default)?

https://github.com/django/django/blob/master/django/utils/timezone.py#L228-L230

That is going to override any timezone we set.

@mscansian
Copy link

I uderstand the issue and kinda see what is happening, but I have no clue if there's a workaround to this. Yeah, sure I could write the time in UTC, but I think it would hinder the readability of my tests. Am I missing something?

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

3 participants