Opened 13 years ago

Closed 13 years ago

#17463 closed Bug (fixed)

timezones tests fail on Windows

Reported by: Karen Tracey Owned by: Aymeric Augustin
Component: Core (Other) Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If I run the timezones tests on a Windows machine where the system timezone is set to US/Eastern (my local time), I get 15 failures:

======================================================================
FAIL: test_change_editable (modeltests.timezones.tests.AdminTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 906, in test_change_editable
    self.assertContains(response, e.dt.astimezone(EAT).time().isoformat())
  File "C:\Users\kmtracey\django\trunk\django\test\testcases.py", line 536, in assertContains
    msg_prefix + "Couldn't find '%s' in response" % text)
AssertionError: Couldn't find '13:20:30' in response

======================================================================
FAIL: test_change_readonly (modeltests.timezones.tests.AdminTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 920, in test_change_readonly
    self.assertContains(response, t.created.astimezone(EAT).isoformat())
  File "C:\Users\kmtracey\django\trunk\django\test\testcases.py", line 536, in assertContains
    msg_prefix + "Couldn't find '%s' in response" % text)
AssertionError: Couldn't find '2011-12-25T23:46:22.104000+03:00' in response

======================================================================
FAIL: test_changelist (modeltests.timezones.tests.AdminTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 894, in test_changelist
    self.assertContains(response, e.dt.astimezone(EAT).isoformat())
  File "C:\Users\kmtracey\django\trunk\django\test\testcases.py", line 536, in assertContains
    msg_prefix + "Couldn't find '%s' in response" % text)
AssertionError: Couldn't find '2011-09-01T13:20:30+03:00' in response

======================================================================
FAIL: test_naive_datetime (modeltests.timezones.tests.NewDatabaseTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 252, in test_naive_datetime
    self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
AssertionError: datetime.datetime(2011, 9, 1, 17, 20, 30, tzinfo=<django.utils.timezone.UTC object at 0x0000000003228C50>) != datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=+0300)

======================================================================
FAIL: test_naive_datetime_with_microsecond (modeltests.timezones.tests.NewDatabaseTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\django\test\testcases.py", line 729, in skip_wrapper
    return test_func(*args, **kwargs)
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 266, in test_naive_datetime_with_microsecond
    self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
AssertionError: datetime.datetime(2011, 9, 1, 17, 20, 30, 405060, tzinfo=<django.utils.timezone.UTC object at 0x0000000003228C50>) != datetime.datetime(2011, 9, 1, 13, 20, 30, 405060, tzinfo=+0300)

======================================================================
FAIL: test_query_filter_with_naive_datetime (modeltests.timezones.tests.NewDatabaseTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 358, in test_query_filter_with_naive_datetime
    self.assertEqual(Event.objects.filter(dt__exact=dt).count(), 1)
AssertionError: 0 != 1

======================================================================
FAIL: test_form (modeltests.timezones.tests.NewFormsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 844, in test_form
    self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
AssertionError: datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=<django.utils.timezone.LocalTimezone object at 0x0000000003E24748>) != datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=<django.utils.timezone.UTC object at 0x0000000003228C50
>)

======================================================================
FAIL: test_model_form (modeltests.timezones.tests.NewFormsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 878, in test_model_form
    self.assertEqual(e.dt, datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
AssertionError: datetime.datetime(2011, 9, 1, 17, 20, 30, tzinfo=<django.utils.timezone.UTC object at 0x0000000003228C50>) != datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=<django.utils.timezone.UTC object at 0x0000000003228C50>)

======================================================================
FAIL: test_split_form (modeltests.timezones.tests.NewFormsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 873, in test_split_form
    self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
AssertionError: datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=<django.utils.timezone.LocalTimezone object at 0x0000000003E24748>) != datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=<django.utils.timezone.UTC object at 0x0000000003228C50
>)

======================================================================
FAIL: test_date_and_time_template_filters (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 771, in test_date_and_time_template_filters
    self.assertEqual(tpl.render(ctx), "2011-09-01 at 23:20:20")
AssertionError: u'2011-09-01 at 16:20:20' != '2011-09-01 at 23:20:20'

======================================================================
FAIL: test_get_current_timezone_templatetag (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 734, in test_get_current_timezone_templatetag
    self.assertEqual(tpl.render(Context()), "Africa/Nairobi" if pytz else "EAT")
AssertionError: u'Eastern Standard Time' != 'EAT'

======================================================================
FAIL: test_localtime_templatetag_and_filters (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 626, in test_localtime_templatetag_and_filters
    self.assertEqual(actual, expected, '%s / %s: %r != %r' % (k1, k2, actual, expected))
AssertionError: utc / on: u'2011-09-01T06:20:30-04:00|2011-09-01T06:20:30-04:00|2011-09-01T10:20:30+00:00|2011-09-01T17:
20:30+07:00' != 2011-09-01T13:20:30+03:00|2011-09-01T13:20:30+03:00|2011-09-01T10:20:30+00:00|2011-09-01T17:20:30+07:00'

======================================================================
FAIL: test_now_template_tag_uses_current_time_zone (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 796, in test_now_template_tag_uses_current_time_zone
    self.assertEqual(tpl.render(Context({})), "+0300")
AssertionError: u'-0500' != '+0300'

======================================================================
FAIL: test_timezone_templatetag (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 703, in test_timezone_templatetag
    self.assertEqual(tpl.render(ctx), "2011-09-01T13:20:30+03:00|2011-09-01T17:20:30+07:00|2011-09-01T13:20:30+03:00")
AssertionError: u'2011-09-01T06:20:30-04:00|2011-09-01T17:20:30+07:00|2011-09-01T06:20:30-04:00' != '2011-09-01T13:20:30
+03:00|2011-09-01T17:20:30+07:00|2011-09-01T13:20:30+03:00'

======================================================================
FAIL: test_tz_template_context_processor (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 766, in test_tz_template_context_processor
    self.assertEqual(tpl.render(RequestContext(HttpRequest())), "Africa/Nairobi" if pytz else "EAT")
AssertionError: u'Eastern Standard Time' != 'EAT'

----------------------------------------------------------------------
Ran 70 tests in 1.177s

FAILED (failures=15, skipped=18)
Destroying test database for alias 'default' (':memory:')...
Destroying test database for alias 'other' (':memory:')...

I think the problem is that these tests set the settings.TIME_ZONE value to an Eastern African value and expect that the underlying OS will start respecting that settings. Per a note on the TIME_ZONE setting here: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone we don't actually support, on Windows, setting TIME_ZONE in settings to something that does not match the actual system time zone.

If I set the system timezone to Nairobi, things are better but still not all-pass:

C:\Users\kmtracey\django\trunk\tests>runtests.py -v2 --settings=test_sqlite timezones
Importing application timezones
Creating test database for alias 'default' (':memory:')...
Creating tables ...
Creating table django_content_type
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_site
Creating table django_flatpage_sites
Creating table django_flatpage
Creating table django_redirect
Creating table django_session
Creating table django_comments
Creating table django_comment_flags
Creating table django_admin_log
Creating table timezones_event
Creating table timezones_maybeevent
Creating table timezones_timestamp
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Creating test database for alias 'other' (':memory:')...
Creating tables ...
Creating table django_content_type
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_site
Creating table django_flatpage_sites
Creating table django_flatpage
Creating table django_redirect
Creating table django_session
Creating table django_comments
Creating table django_comment_flags
Creating table django_admin_log
Creating table timezones_event
Creating table timezones_maybeevent
Creating table timezones_timestamp
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
test_change_editable (modeltests.timezones.tests.AdminTests) ... ok
test_change_editable_in_other_timezone (modeltests.timezones.tests.AdminTests) ... ok
test_change_readonly (modeltests.timezones.tests.AdminTests) ... ok
test_change_readonly_in_other_timezone (modeltests.timezones.tests.AdminTests) ... ok
test_changelist (modeltests.timezones.tests.AdminTests) ... ok
test_changelist_in_other_timezone (modeltests.timezones.tests.AdminTests) ... ok
test_auto_now_and_auto_now_add (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_aware_datetime_in_local_timezone (modeltests.timezones.tests.LegacyDatabaseTests) ... skipped "Database doesn't support feature supports_timezones"
test_aware_datetime_in_local_timezone_with_microsecond (modeltests.timezones.tests.LegacyDatabaseTests) ... skipped "Database doesn't support feature supports_timezones"
test_aware_datetime_in_local_timezone_with_microsecond_unsupported (modeltests.timezones.tests.LegacyDatabaseTests) ...
skipped "Database doesn't support feature supports_timezones"
test_aware_datetime_in_other_timezone (modeltests.timezones.tests.LegacyDatabaseTests) ... skipped "Database doesn't support feature supports_timezones"
test_aware_datetime_in_other_timezone_unsupported (modeltests.timezones.tests.LegacyDatabaseTests) ... skipped "Database doesn't support feature supports_timezones"
test_aware_datetime_in_utc (modeltests.timezones.tests.LegacyDatabaseTests) ... skipped "Database doesn't support feature supports_timezones"
test_aware_datetime_in_utc_unsupported (modeltests.timezones.tests.LegacyDatabaseTests) ... skipped "Database doesn't support feature supports_timezones"
test_aware_datetime_unspported (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_naive_datetime (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_naive_datetime_with_microsecond (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_naive_datetime_with_microsecond_unsupported (modeltests.timezones.tests.LegacyDatabaseTests) ... skipped 'Database has feature supports_microsecond_precision'
test_query_aggregation (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_query_date_related_filters (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_query_dates (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_query_filter (modeltests.timezones.tests.LegacyDatabaseTests) ... ok
test_form (modeltests.timezones.tests.LegacyFormsTests) ... ok
test_form_with_ambiguous_time (modeltests.timezones.tests.LegacyFormsTests) ... skipped 'this test requires pytz'
test_form_with_non_existent_time (modeltests.timezones.tests.LegacyFormsTests) ... skipped 'this test requires pytz'
test_model_form (modeltests.timezones.tests.LegacyFormsTests) ... ok
test_split_form (modeltests.timezones.tests.LegacyFormsTests) ... ok
test_auto_now_and_auto_now_add (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_aware_datetime_in_local_timezone (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_aware_datetime_in_local_timezone_with_microsecond (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_aware_datetime_in_local_timezone_with_microsecond_unsupported (modeltests.timezones.tests.NewDatabaseTests) ... skipped 'Database has feature supports_microsecond_precision'
test_aware_datetime_in_other_timezone (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_aware_datetime_in_utc (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_naive_datetime (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_naive_datetime_with_microsecond (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_naive_datetime_with_microsecond_unsupported (modeltests.timezones.tests.NewDatabaseTests) ... skipped 'Database has feature supports_microsecond_precision'
test_null_datetime (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_query_aggregation (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_query_date_related_filters (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_query_dates (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_query_filter (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_query_filter_with_naive_datetime (modeltests.timezones.tests.NewDatabaseTests) ... ok
test_query_filter_with_pytz_timezones (modeltests.timezones.tests.NewDatabaseTests) ... skipped 'this test requires pytz'
test_form (modeltests.timezones.tests.NewFormsTests) ... ok
test_form_with_ambiguous_time (modeltests.timezones.tests.NewFormsTests) ... skipped 'this test requires pytz'
test_form_with_non_existent_time (modeltests.timezones.tests.NewFormsTests) ... skipped 'this test requires pytz'
test_form_with_other_timezone (modeltests.timezones.tests.NewFormsTests) ... ok
test_model_form (modeltests.timezones.tests.NewFormsTests) ... ok
test_split_form (modeltests.timezones.tests.NewFormsTests) ... ok
test_aware_datetime_in_local_timezone (modeltests.timezones.tests.SerializationTests) ... ok
test_aware_datetime_in_other_timezone (modeltests.timezones.tests.SerializationTests) ... ok
test_aware_datetime_in_utc (modeltests.timezones.tests.SerializationTests) ... ok
test_aware_datetime_with_microsecond (modeltests.timezones.tests.SerializationTests) ... ok
test_naive_datetime (modeltests.timezones.tests.SerializationTests) ... ok
test_naive_datetime_with_microsecond (modeltests.timezones.tests.SerializationTests) ... ok
test_date_and_time_template_filters (modeltests.timezones.tests.TemplateTests) ... ok
test_date_and_time_template_filters_honor_localtime (modeltests.timezones.tests.TemplateTests) ... ok
test_get_current_timezone_templatetag (modeltests.timezones.tests.TemplateTests) ... FAIL
test_get_current_timezone_templatetag_invalid_argument (modeltests.timezones.tests.TemplateTests) ... ok
test_get_current_timezone_templatetag_with_pytz (modeltests.timezones.tests.TemplateTests) ... skipped 'this test requires pytz'
test_localtime_filters_do_not_raise_exceptions (modeltests.timezones.tests.TemplateTests) ... ok
test_localtime_filters_with_pytz (modeltests.timezones.tests.TemplateTests) ... skipped 'this test requires pytz'
test_localtime_templatetag_and_filters (modeltests.timezones.tests.TemplateTests) ... ok
test_localtime_templatetag_invalid_argument (modeltests.timezones.tests.TemplateTests) ... ok
test_localtime_with_time_zone_setting_set_to_none (modeltests.timezones.tests.TemplateTests) ... ok
test_now_template_tag_uses_current_time_zone (modeltests.timezones.tests.TemplateTests) ... ok
test_timezone_templatetag (modeltests.timezones.tests.TemplateTests) ... ok
test_timezone_templatetag_invalid_argument (modeltests.timezones.tests.TemplateTests) ... ok
test_timezone_templatetag_with_pytz (modeltests.timezones.tests.TemplateTests) ... skipped 'this test requires pytz'
test_tz_template_context_processor (modeltests.timezones.tests.TemplateTests) ... FAIL

======================================================================
FAIL: test_get_current_timezone_templatetag (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 734, in test_get_current_timezone_temp
latetag
    self.assertEqual(tpl.render(Context()), "Africa/Nairobi" if pytz else "EAT")
AssertionError: u'E. Africa Standard Time' != 'EAT'

======================================================================
FAIL: test_tz_template_context_processor (modeltests.timezones.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\modeltests\timezones\tests.py", line 766, in test_tz_template_context_proce
ssor
    self.assertEqual(tpl.render(RequestContext(HttpRequest())), "Africa/Nairobi" if pytz else "EAT")
AssertionError: u'E. Africa Standard Time' != 'EAT'

----------------------------------------------------------------------
Ran 70 tests in 1.060s

FAILED (failures=2, skipped=18)
Destroying test database for alias 'default' (':memory:')...
Destroying test database for alias 'other' (':memory:')...

Those 2 look fairly innocuous/fixable, but I'm not entirely sure how to approach fixing these tests in general. It seems the issue is in the tests, not in the underlying new timezone support code. The tests are assuming they can set TIME_ZONE different than the underlying system time, and we don't support that on Windows.....

Attachments (1)

17463.diff (6.7 KB ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by Aymeric Augustin, 13 years ago

Owner: changed from nobody to Aymeric Augustin
Triage Stage: UnreviewedAccepted

So the problem boils down to:

  • testing with settings.TIME_ZONE == system time zone is deceptive — some tests can pass by pure luck. That's one reason why I chose EAT, an uncommon timezone, the other reason being that it doesn't have DST.
  • Windows doesn't support settings.TIME_ZONE != system time zone.

As explained here, not only are the names of timezones non-standard, but they're also local-dependant! So there's no decent way we can fix the two failures you got after switching the system time zone to Nairobi.

I'm not sure how to proceed. I'll probably end up skipping problematic tests under Windows and maybe adding a few Windows-specific tests.

comment:2 by Aymeric Augustin, 13 years ago

Has patch: set

by Aymeric Augustin, 13 years ago

Attachment: 17463.diff added

comment:3 by Aymeric Augustin, 13 years ago

Resolution: fixed
Status: newclosed

In [17278]:

Fixed #17463 -- Conditionally skipped tests that Windows isn't able to run.

Note: See TracTickets for help on using tickets.
Back to Top