Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#17312 closed Cleanup/optimization (fixed)

Testing examples should use django.utils.TestCase

Reported by: jcspray@… Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: krw1243 Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The 'Testing Django applications page' (https://docs.djangoproject.com/en/dev/topics/testing/) gives many examples of tests using unittest2.TestCase directly rather than django.test.TestCase.

For the DB to be reset between tests it is essential to use django.test.TestCase, and that is not made at all obvious in this documentation.

  • At least: a prominent warning should be present about the fact that DB side effects are possible when using unittest2.TestCase
  • Preferably: the examples should use django.utils.TestCase since it is a safer default.

Attachments (1)

17312.diff (2.1 KB ) - added by Tim Graham 11 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by krw1243, 12 years ago

Cc: krw1243 added

comment:2 by Preston Holmes, 12 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Aymeric Augustin, 12 years ago

Triage Stage: AcceptedDesign decision needed

Within Django itself, the convention is to use unittest.TestCase for tests that don't need django.test.TestCase, although I'm not entirely sure about the reason (performance?).

I'd like to see a benchmark before recommending to use django.test.TestCase unconditionally.

Last edited 12 years ago by Aymeric Augustin (previous) (diff)

comment:4 by Preston Holmes, 12 years ago

As the differences are already documented: https://docs.djangoproject.com/en/dev/topics/testing/#testcase

perhaps it would suffice just to have a quick note about database effects and a forward link to that section of the docs at the bottom of the introduction "writing unit tests" (just before the "writing doctests" section)

https://docs.djangoproject.com/en/dev/topics/testing/#writing-unit-tests.

by Tim Graham, 11 years ago

Attachment: 17312.diff added

comment:5 by Tim Graham, 11 years ago

Has patch: set
Triage Stage: Design decision neededAccepted

I think a warning is definitely appropriate. In fact, the current example has database side effects.

comment:6 by Claude Paroz, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 7df03268a467a9aec9c4c574c85317a738ca33ae:

Fixed #17312 - Warned about database side effects in tests.

Thanks jcspray for the suggestion.

comment:8 by Tim Graham <timograham@…>, 11 years ago

In 2545dc59bf44131a1f60f7393f29f025939f3a09:

[1.5.x] Fixed #17312 - Warned about database side effects in tests.

Thanks jcspray for the suggestion.

Backport of 7df03268a467a9aec9c4c574c85317a738ca33ae from master.

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