Opened 5 years ago

Closed 5 years ago

Last modified 5 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: master
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 5 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 5 years ago by Paul McMillan

Severity: NormalRelease blocker

comment:2 Changed 5 years ago by Aymeric Augustin

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

comment:3 Changed 5 years ago by Aymeric Augustin

Owner: changed from nobody to Aymeric Augustin

comment:4 Changed 5 years ago by Ramiro Morales

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 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by Aymeric Augustin

In [17154]:

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

comment:8 Changed 5 years ago by Aymeric Augustin

Owner: changed from Aymeric Augustin to nobody

DateTimeField no longer sends warnings in the test suite.

comment:9 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset
Needs tests: unset

The localflavor warnings appeared after r17009:

Attached patch removes the warnings. What do you think?

Changed 5 years ago by Aymeric Augustin

Attachment: 17275.diff added

comment:10 Changed 5 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:11 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by anonymous

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 Changed 5 years ago by Steve Lacy

Cc: slacy@… added

comment:14 Changed 5 years ago by Aymeric Augustin

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