Opened 4 years ago

Closed 2 years ago

#15896 closed Bug (wontfix)

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

Reported by: RoySmith 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 Changed 4 years ago by jonash

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 4 years ago by RoySmith

  • Resolution invalid deleted
  • Status changed from closed to reopened

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 Changed 4 years ago by jonash

  • Resolution set to invalid
  • Status changed from reopened to closed

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 Changed 2 years ago by tuomas.salo@…

  • Resolution invalid deleted
  • Status changed from closed to new
  • 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 Changed 2 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to closed

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