Opened 12 years ago

Closed 11 years ago

#19885 closed Cleanup/optimization (fixed)

Make all testing tools importable from django.test

Reported by: Anssi Kääriäinen Owned by: Kevin Christopher Henry
Component: Testing framework Version: dev
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?

Change History (4)

comment:1 by Carl Meyer, 12 years ago

Triage Stage: UnreviewedAccepted

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 by Kevin Christopher Henry, 11 years ago

Owner: changed from nobody to Kevin Christopher Henry
Status: newassigned

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 by Tim Graham, 11 years ago

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 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

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.

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