Opened 7 years ago

Closed 7 years ago

#6143 closed (wontfix)

provide doctest build helper

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

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 akaihola 7 years ago.
suggested patch

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by akaihola

suggested patch

comment:1 Changed 7 years ago by Simon G <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by russellm

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

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