Opened 14 years ago

Closed 12 years ago

#15896 closed Bug (wontfix)

unittest docs say import django.utils, should be djanto.test

Reported by: Roy Smith Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

At http://docs.djangoproject.com/en/1.3/topics/testing/#writing-unit-tests, it says:

from django.utils import unittest

It should import from django.test, no? It's wrong in the release notes too. The sample tests.py file gets it right.

Change History (5)

comment:1 by Jonas H., 14 years ago

Resolution: invalid
Status: newclosed

Ever tried to do so?

>>> from django.test import unittest
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
ImportError: cannot import name unittest

comment:2 by Roy Smith, 14 years ago

Resolution: invalid
Status: closedreopened

Hmm, OK, I read this a little more carefully and see what had me going. The docs say:

from django.utils import unittest

but the sample tests.py file says:

from django.test import TestCase

this is a little confusing. It would be more obvious if the sample and the docs did it the same way.

comment:3 by Jonas H., 14 years ago

Resolution: invalid
Status: reopenedclosed

It's a different thing. django.utils.unittest is a copy of the unittest2 package for Python < 2.7. django.test holds Django's special testsuite helpers.

In most cases you don't need to import anything from django.utils.unittest. It's just some kind of warning to prevent you from using import unittest.

comment:4 by tuomas.salo@…, 12 years ago

Resolution: invalid
Status: closednew
UI/UX: unset

A problem persists. The docs start by samples with from django.utils import unittest, but the example tests.py created by python manage.py startapp says from django.test import TestCase. That might confuse people starting to write tests. The docs do mention something about the difference, but only after a few pagefuls.

comment:5 by Jacob, 12 years ago

Resolution: wontfix
Status: newclosed

They really are two different things, used for two different purposes. I'm going to close this again; if you feel strongly, please take it to django-dev for discussion.

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