Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#15595 closed Bug (fixed)

emphasize the importance of 'from django.test import TestCase'

Reported by: Kenneth Gonsalves Owned by: ShawnMilo
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX:

Description

On reading the dev docs on tests one starts of with importing unittest either directly or from django.utils. The docs should clearly specify at the beginning that the optimal way is to do from django.test import TestCase as this will automatically import unittest2 as well as all the goodies.

Attachments (1)

15595_TestCase_docs.diff (1.1 KB) - added by ShawnMilo 6 years ago.
Changes at Russell's suggestion.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 6 years ago by MikeRamirez

comment:2 Changed 6 years ago by Kenneth Gonsalves

as mike has mentioned, now django ships with import of TestCase from django.test in the sample test file in an app created by startapp. So it makes a case for putting that as default in the documentation.

comment:3 Changed 6 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

No, it isn't a good idea to recommend django.test.TestCase unilaterally. It's a matter of picking the right tool for the job. django.test.TestCase is an extension that contains a number of extra features for testing Django views, etc. However, those extra features have a significant overhead. If you don't need a test database for testing a particular function, you shouldn't be using django.test.testCase.

That said, django.test.TestCase is introduced quite late in the testing docs -- we should probably mention it in passing during the early stages so that the existence of the class isn't lost in the noise.

comment:4 Changed 6 years ago by Luke Plant

Type: Bug

comment:5 Changed 6 years ago by Luke Plant

Severity: Normal

Changed 6 years ago by ShawnMilo

Attachment: 15595_TestCase_docs.diff added

Changes at Russell's suggestion.

comment:6 Changed 6 years ago by ShawnMilo

Easy pickings: set
Has patch: set

comment:7 Changed 6 years ago by anonymous

Should emphasize that you get an empty test database for each test case.

comment:8 in reply to:  7 Changed 6 years ago by ShawnMilo

Replying to anonymous:

Should emphasize that you get an empty test database for each test case.

Do you mean that it should be made clear that the fixtures are refreshed for each test? If so, that's a good point, and non-obvious.

Shawn

comment:9 Changed 6 years ago by ShawnMilo

Owner: changed from nobody to ShawnMilo

comment:10 Changed 6 years ago by Dougal Matthews

Cc: dougal85@… added

comment:11 Changed 6 years ago by Chris Beaven

Resolution: fixed
Status: newclosed

In [16214]:

Fixes #15595 -- emphasize the benefits of django.test.TestCase. Thanks for the patch Shawn Milochik

comment:12 Changed 6 years ago by Chris Beaven

In [16215]:

[1.3.X] Fixes #15595 -- emphasize the benefits of django.test.TestCase. Thanks for the patch Shawn Milochik

Backport of r16214 from trunk.

comment:13 Changed 6 years ago by Dougal Matthews

Cc: dougal85@… removed
Note: See TracTickets for help on using tickets.
Back to Top