This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients r.david.murray
Date 2015-07-30.13:27:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1438262830.97.0.532585638369.issue24756@psf.upfronthosting.co.za>
In-reply-to
Content
I propose that we remove the paragraph before 'run_docstring_exmaples' in the doctest docs.  It says that there's no intent to remove the function but that it is "rarely useful".  However, it is in fact *very* useful, for any code that also uses testmod.

For example, a module I just wrote has this:

    if __name__ == '__main__':
        import doctest
        flags = doctest.REPORT_NDIFF|doctest.FAIL_FAST
        if len(sys.argv) > 1:
            name = sys.argv[1]
            if name in globals():
                obj = globals()[name]
            else:
                obj = __test__[name]
            doctest.run_docstring_examples(obj, globals(), name=name,
                                           optionflags=flags)
        else:
            fail, total = doctest.testmod(optionflags=flags)
            print("{} failures out of {} tests".format(fail, total))


This makes the module its own test runner: if I get doctest failures, I can re-run a *specific* doctest while debugging the problem, and is the obvious application of run_docstring_examples.

The attached patch also clarifies the fact that it works on strings.  It also adds the above example to the soapbox section of the docs.  I'm less interested in that change than in the clarification that strings work :)

Someday perhaps I'll propose the addition of the equivalent to unittest.main for doctest.
History
Date User Action Args
2015-07-30 13:27:11r.david.murraysetrecipients: + r.david.murray
2015-07-30 13:27:10r.david.murraysetmessageid: <1438262830.97.0.532585638369.issue24756@psf.upfronthosting.co.za>
2015-07-30 13:27:10r.david.murraylinkissue24756 messages
2015-07-30 13:27:10r.david.murraycreate