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 inmodels.py
ortests.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)
Change History (3)
by , 17 years ago
Attachment: | test-simple-refactor.diff added |
---|
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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.
suggested patch