#21161 closed Bug (fixed)

Windows doesn't have tzset, regression added with d9413d33b2a8371731a92289123683cf6f440290

Reported by: manfre Owned by: anonymous
Component: Utilities Version: master
Severity: Release blocker Keywords: timezones pytz
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Changeset d9413d33b2a8371731a92289123683cf6f440290 breaks a few tests on Windows using sqlite with pytz installed. Tests do not fail without pytz.

======================================================================
FAIL: test_templates (template_tests.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\django\django\tests\template_tests\tests.py", line 621, in test_templates
    ('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
AssertionError: Tests failed:
----------------------------------------------------------------------
Template test (Cached='False', TEMPLATE_STRING_IF_INVALID='', TEMPLATE_DEBUG=False): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
----------------------------------------------------------------------
Template test (Cached='True', TEMPLATE_STRING_IF_INVALID='', TEMPLATE_DEBUG=False): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
----------------------------------------------------------------------
Template test (Cached='False', TEMPLATE_STRING_IF_INVALID='INVALID', TEMPLATE_DEBUG=False): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
----------------------------------------------------------------------
Template test (Cached='True', TEMPLATE_STRING_IF_INVALID='INVALID', TEMPLATE_DEBUG=False): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
----------------------------------------------------------------------
Template test (Cached='False', TEMPLATE_STRING_IF_INVALID='', TEMPLATE_DEBUG=True): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
----------------------------------------------------------------------
Template test (Cached='True', TEMPLATE_STRING_IF_INVALID='', TEMPLATE_DEBUG=True): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
 
======================================================================
FAIL: test_datetime_with_local_tzinfo (utils_tests.test_dateformat.DateFormatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\django\django\tests\utils_tests\test_dateformat.py", line 39, in test_datetime_with_local_tzinfo
    self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt.replace(tzinfo=None))
AssertionError: datetime.datetime(2009, 5, 15, 23, 30, 30) != datetime.datetime(2009, 5, 16, 5, 30, 30)
 
======================================================================
FAIL: test_datetime_with_tzinfo (utils_tests.test_dateformat.DateFormatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\django\django\tests\utils_tests\test_dateformat.py", line 48, in test_datetime_with_tzinfo
    self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt.astimezone(ltz).replace(tzinfo=None))
AssertionError: datetime.datetime(2009, 5, 15, 23, 30, 30) != datetime.datetime(2009, 5, 16, 5, 30, 30)

From IRC:

mYk: "you can't set a timezone that isn't the system timezone on Windows (no tzset)"
mYk: "can you file a ticket? that's a release blocker"

Attachments (1)

fix-21161-no-tzset-on-windows.patch (5.7 KB) - added by xelnor 21 months ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 22 months ago by aaugustin

  • Component changed from Testing framework to Utilities
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to anonymous
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

Maybe my hunch isn't correct, but in any case it's a regression I introduced and I have to fix.

comment:2 Changed 21 months ago by xelnor

  • Has patch set

The utils_tests.test_dateformat.DateFormatTests tests have been fixed in 79ccd1a101e6379c5a49da18fc006816e5ed127c.

The tests in template_tests check comparisons between a timezone-aware datetime.datetime.now() and datetime.datetime.now(), thus relying on a valid tzset() function (or having the system TZ set to America/Chicago).

Moreover, they are duplicating the unit tests in tests/utils_tests/test_timesince.py, which didn't fail on Windows when the system timezone is behing America/Chicago.

The attached patch:

  • Disables the template_tests relying on tzset availability
  • Adds missing tests in tests/utils_tests/test_timesince.py for situations where the current timezone is behing America/Chicago
  • Disables those new tests on systems lacking tzset (e.g Windows).

Changed 21 months ago by xelnor

comment:3 Changed 21 months ago by aaugustin

I've updated the patch to use the versions of TZ_SUPPORT and @requires_tz_support from django.test.utils and I've run the tests on Windows. I'll commit shortly.

comment:4 Changed 21 months ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 671757b507a60330ee37ef749a3f3a0301258f88:

Fixed #21161 -- Timezone-related tests on Windows.

Thanks Xelnor for the patch.

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