Opened 17 years ago

Closed 17 years ago

#6143 closed (wontfix)

provide doctest build helper

Reported by: Antti Kaihola Owned by: nobody
Component: Testing framework Version: dev
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I suggest a tiny refactoring to the django.test.simple module: extract the doctest.DocTestSuite() call to its own function and use that in build_suite() twice.

This provides two benefits:

  • DRY in django.test.simple
  • doctest suite creation shortcut for suite() function in models.py or tests.py

Currently to include a doctest for an arbitrary module in the custom test suite, one must do:

from unittest import TestSuite
from django.test import _doctest as doctest
from django.test.simple import doctestOutputChecker
from django.test.testcases import DocTestRunner
import mymodule

def suite()
    suite = TestSuite()
    suite.addTest(doctest.DocTestSuite(
        mymodule,
        checker=doctestOutputChecker,
        runner=DocTestRunner))
    return suite

This refactoring simplifies the above to just:

from unittest import TestSuite
from django.test.simple import build_doctest_suite
import mymodule

def suite()
    suite = TestSuite()
    suite.addTest(build_doctest_suite(mymodule))
    return suite

Attachments (1)

test-simple-refactor.diff (1.8 KB ) - added by Antti Kaihola 17 years ago.
suggested patch

Download all attachments as: .zip

Change History (3)

by Antti Kaihola, 17 years ago

Attachment: test-simple-refactor.diff added

suggested patch

comment:1 by Simon G <dev@…>, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Russell Keith-Magee, 17 years ago

Resolution: wontfix
Status: newclosed

This seems like overkill to me. The repetition it removes isn't around a complex block of code that could be a serious maintenance problem - it's a single duplicated function call, with a common set of arguments. If you're building a custom test suite, I would argue that you should be explicitly making a decision on your Doctest arguments; the 'use the same defaults as Django' isn't a strong enough use case in my book.

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