[TIP] unittest2 discovery / doctest integration?
Olemis Lang
olemis at gmail.com
Thu Apr 29 06:32:44 PDT 2010
On Wed, Apr 28, 2010 at 4:26 PM, Pete <pfein at pobox.com> wrote:
> On Apr 28, 2010, at 10:27 AM, Pete wrote:
>
>> Just wondering how to go about running doctests under unittest2's discovery... The approach mentioned here http://docs.python.org/dev/library/doctest.html#unittest-api gets the doctests run, but is kinda bogus (you get 2 sets of test runner output). Glancing at unittest2's discovery stuff, it seems to look for TestCases, but not TestSuites. Just wondering if there's something obvious I'm missing, or if I should start poking through/ripping off doctest's implementation of integration (which is lightly documented).
>
> Appears the way to do this goes like so. In your mostly-unittests test module, define a load_tests:
>
> def load_tests(loader, tests, ignore):
> tests.addTests(doctest.DocTestSuite(module_with_doctests))
> return tests
>
JFTR and pseudo-OT, using `dutest` you could do
{{{
#!python
def load_tests(loader, tests, ignore):
from dutest import defaultTestLoader
tests.addTests(defaultTestLoader.loadTestsFromModule(module_with_doctests))
return tests
}}}
and then you'll load both instantiated unittests TCs as well as TCs
(wrappers) to run your your doctests (with enhanced test reports as a
side effect ;o) . You could also specify more sophisticated things
like setting up doctest flags (e.g. REPORT_UDIFF) , and more ... but
this is JFTR
;o)
--
Regards,
Olemis.
Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/
Featured article:
More information about the testing-in-python
mailing list