#17312 closed Cleanup/optimization (fixed)
Testing examples should use django.utils.TestCase
Reported by: | 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)
Change History (9)
comment:1 by , 13 years ago
Cc: | added |
---|
comment:2 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 13 years ago
Triage Stage: | Accepted → Design decision needed |
---|
comment:4 by , 13 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 , 12 years ago
Attachment: | 17312.diff added |
---|
comment:5 by , 12 years ago
Has patch: | set |
---|---|
Triage Stage: | Design decision needed → Accepted |
I think a warning is definitely appropriate. In fact, the current example has database side effects.
comment:6 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Within Django itself, the convention is to use
unittest.TestCase
for tests that don't needdjango.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
unilaterally.