Use django.test.TestCase for first testing example #1006

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants

lorin commented Apr 10, 2013

This doc change switches from unittest.TestCase to django.test.TestCase
with some accompanying text changes.

See https://code.djangoproject.com/ticket/20165

@lorin lorin Use django.test.TestCase for first testing example
This doc change switches from unittest.TestCase to django.test.TestCase
with some accompanying text changes.

Motivation: you are very likely to get journeyman "drive-by" Django
developers just looking for a simple template example of how to write
a unit test, they will find this canonical example, copy-paste it,
and then get burned because of database coupling.

These type of readers won't read the warning that appears below the
text.
40703ac

+1 As that "drive-by" Django developer, I have to say the existing first entire screen of documentation is just plain technically wrong.
The first green box shows:

from django.utils import unittest

The first green-box example uses the same premature optimization that causes errors and strange side-effects once someone tries to write a more complex unit test than "hello world". I had to scroll down on my laptop to see the warning that the first example doesn't work if you actually save() the model.

timgraham closed this May 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment