Code

#19885 closed Cleanup/optimization (fixed)

Make all testing tools importable from django.test

Reported by: akaariai Owned by: marfire
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently it is nearly impossible to remember which module has which testing item. For example:

  • expectedFailure, skipUnlessDBFeature, ... is from django.test
  • skipIf is from django.utils.unittest
  • override_setting is from django.test.utils
  • parse_html from django.test.html

I can't remember where to import these. I will always do a git grep in the test directory to see the correct import location. I would like to be able to import everything from django.test. Or at least django.utils.unittest.* + override_settings.

Is there some reason for the current split?

Attachments (0)

Change History (4)

comment:1 Changed 17 months ago by carljm

  • Triage Stage changed from Unreviewed to Accepted

We backported unittest2 into the Django codebase as django.utils.unittest because it is only available in the standard library of Python 2.7+. When we drop support for Python 2.6, we will get rid of django.utils.unittest entirely. I wouldn't have any problem with importing a common utility like skipIf into django/test/__init__.py in parallel with the other skip-related utilities imported there; that will actually reduce the amount of search and replace we have to do when we switch from using django.utils.unittest to stdlib unittest.

Similarly I'd be fine importing override_settings (and anything else from django.test.utils that is commonly used) into django/test/__init__.py.

I don't feel quite so good about doing that with parse_html; HTML-parsing is a separate niche that many tests don't need, it makes sense to me to keep that segregated in django.test.html.

comment:2 Changed 10 months ago by marfire

  • Owner changed from nobody to marfire
  • Status changed from new to assigned

I think the Testing Django applications document provides a good basis for deciding what's common enough to fall under django.test. Taking that as a basis, and taking into account that much of it is already imported into __init__.py (and that django.utils.unittest is no longer necessary in 1.7), I propose the following changes:

  • make override_settings available on django.test.
  • update the documentation to consistently use the django.test versions (for example, right now it references both django.test.Client and django.test.client.Client).
  • remove Approximate from django.test (and update the few references to it accordingly). This is undocumented and seemingly little used, so it makes more sense to leave it at django.test.utils.

comment:3 Changed 10 months ago by timo

  • Has patch set

I've left a couple minor comments on the pull request regarding cleaning up the docs, otherwise the proposal looks good to me.

comment:4 Changed 10 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 9d700322b38ea670800a97f2b92dd2fc2c6ff28d:

Fixed #19885 -- cleaned up the django.test namespace

  • override_settings may now be imported from django.test
  • removed Approximate from django.test
  • updated documentation for things importable from django.test

Thanks akaariai for the suggestion.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.