Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#17275 closed Cleanup/optimization (fixed)

Fix RuntimeWarning in the Django test suite

Reported by: Paul McMillan Owned by: nobody
Component: Testing framework Version: dev
Severity: Release blocker Keywords:
Cc: slacy@… Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django's test suite currently raises a RuntimeWarning in several places. The localflavor re-arrangement in r16680 may have borked the warning supression for ca/ca_provinces and id/id_choices (or it may have happened earlier in the history, I didn't hunt the exact changeset down).

Additionally, the DateTimeField raises RuntimeWarning in several tests after the timezone refactor.

In any case, we know we changed those things, so warning ourselves in our own test suite is silly.

Attachments (1)

17275.diff (2.8 KB ) - added by Aymeric Augustin 12 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 by Paul McMillan, 12 years ago

Severity: NormalRelease blocker

comment:2 by Aymeric Augustin, 12 years ago

I'll deal with the warnings related to time-zone support. They were introduced at r17117.

comment:3 by Aymeric Augustin, 12 years ago

Owner: changed from nobody to Aymeric Augustin

comment:4 by Ramiro Morales, 12 years ago

The localflavor-related warnings actually started appearing after r17009. E.g. imports of django/contrib/localflavor/id/id_choices.py (the one raising the warning at the module level) in django/contrib/localflavor/id/forms.py were moved from class level to module level and so the RuntimeWarning is triggered when contrib.localflavor.id is simply imported.

I don't think they can be filtered out in this condition. Maybe we can move these imports back to the class level?

Something similar happens with the ca localflavor.

comment:5 by Aymeric Augustin, 12 years ago

The warnings related to time-zone support are caused by initial_data fixtures that contain naive datetimes.

The solution is two-fold:

  • rename initial_data fixtures and load them specifically in the tests that need them;
  • change the tests of the initial_data feature itself to use a fixture that doesn't contain datetimes.

comment:6 by Aymeric Augustin, 12 years ago

In [17153]:

Renamed the fixtures used by the aggregation tests so they're only loaded by the tests that use them. Refs #17275.

comment:7 by Aymeric Augustin, 12 years ago

In [17154]:

Changed the fixtures used to test the 'initial_data' feature so they don't contain datetimes. Refs #17275.

comment:8 by Aymeric Augustin, 12 years ago

Owner: changed from Aymeric Augustin to nobody

DateTimeField no longer sends warnings in the test suite.

comment:9 by Aymeric Augustin, 12 years ago

Easy pickings: unset
Needs tests: unset

The localflavor warnings appeared after r17009:

Attached patch removes the warnings. What do you think?

by Aymeric Augustin, 12 years ago

Attachment: 17275.diff added

comment:10 by Jannis Leidel, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:11 by Aymeric Augustin, 12 years ago

Resolution: fixed
Status: newclosed

In [17164]:

Fixed #17275 -- Moved some imports back from module level to class level to prevent the test suite from raising warnings.

comment:12 by anonymous, 12 years ago

I'm just switching our codebase to 1.4c2 and have run into this issue in the test suites.

To make sure it wasn't something I was doing, I did the following:

$ django-admin.py startproject blank 
$ cd blank/blank
$ <edit settings.py and set DB ENGINE to 'django.db.backends.sqlite3'
$ django-admin.py test 

Creating test database for alias 'default'...
..../home/slacy/src/oswebsite/wsve/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2007-05-30 13:20:10) while time zone support is active.
  RuntimeWarning)
...../home/slacy/src/oswebsite/wsve/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2006-12-17 07:03:31) while time zone support is active.
  RuntimeWarning)
........................../home/slacy/src/oswebsite/wsve/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-01-13 00:14:00) while time zone support is active.
  RuntimeWarning)
...............................................................................................................................................................................................................................................................................................................s.......................................................................
----------------------------------------------------------------------
Ran 410 tests in 10.039s

OK (skipped=1)
Destroying test database for alias 'default'...

comment:13 by Steve Lacy, 12 years ago

Cc: slacy@… added

comment:14 by Aymeric Augustin, 12 years ago

This is a different issue, I've moved it to its own ticket: #17940.

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