[TIP] unittest2 discovery / doctest integration?
pfein at pobox.com
Wed Apr 28 14:26:00 PDT 2010
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):
Pretty straightforward, though not at all obvious. Looks like the documentation for doctest could use an update... http://docs.python.org/dev/library/doctest.html#unittest-api I'd write a patch (hello-to-my-friend-jesse-noller), but I'm not entirely sure what to say (tl;dr) - would replacing the code sample & changing its description to read "To integrate with unittest discovery, include the following in a module of unittests:" suffice?
As for Jim's comment re: "I wish I'd used TestCases instead of TestSuites for doctest integration"... I'm gonna have to disagree. The problem is that there can be multiple doctests->TestCases generated by DocTestSuite/DocFileSuite. As discovery currently works by inspecting the module dict, there's not good way to bind those to multiple names. Arguably, discovery should look for TestSuites as well...
More information about the testing-in-python