Opened 16 years ago
Closed 16 years ago
#7978 closed (fixed)
Contrib.Sites doctest assumes existence of current site
Reported by: | evan_schulz | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Keywords: | sites doctest | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
django.contrib.sites.tests contains the following test checking that the get_current method throws an exception if the current record doesn't exist:
>>> s = Site.objects.get_current() ... >>> s.delete() >>> Site.objects.get_current() Traceback (most recent call last): ... DoesNotExist: Site matching query does not exist. """
The problem is that the default Site record (added when the table is created) is deleted by this doctest. This creates an inconsistency when running "./manage.py test" as any test cases run before the contrib.sites test case will have a valid current_site() while those that run after won't. This can be even more confusing for someone creating test cases as running tests for an individual app ("./manage.py test myapp") may work fine while running test cases for all apps could fail (once this sites doctest gets thrown into the mix).
Proposal: Restore the default Site record at the end of the sites doctest so that other test cases can assume the record will be there (as the sites, auth, and possibly other contrib tests already do).
Attachments (1)
Change History (4)
comment:1 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
by , 16 years ago
Attachment: | sites_test.diff added |
---|
comment:2 by , 16 years ago
Has patch: | set |
---|---|
Resolution: | wontfix |
Status: | closed → reopened |
Summary: | Contrib.Sites doctest deletes current site → Contrib.Sites doctest assumes existence of current site |
Fair enough -- since the sites doctest currently requires a site instance to operate without ensuring that the initial data exists I've attached a patch updating the test
comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
It's not the responsibility of doctests to make sure that they have no net impact. If a test requires a site instance to operate cleanly, then that test case should ensure that the site instance is available. Test should not assume that other tests have left the database in a particular state. This means that each test should manually create the object it requires, or invoke the flush command to ensure that initial data exists as expected.
If you can point at a specific test case in the Django suite that is affected by the non-existence of Site, reopen this ticket with the details of the affected test. If the failure is with your own test, you need to update the test.