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.

classification
Title: doctest run_docstring_examples does have an obvious utility
Type: enhancement Stage: resolved
Components: Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ethan.furman, python-dev, r.david.murray, terry.reedy
Priority: normal Keywords: patch

Created on 2015-07-30 13:27 by r.david.murray, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
remove_doctest_run_docstring_examples_gloss.patch r.david.murray, 2015-07-30 13:27 review
Messages (4)
msg247667 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-07-30 13:27
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.
msg247668 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-07-30 13:36
Looks good to me.
msg247784 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-31 22:51
Ditto
msg250936 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-18 05:22
New changeset 64d48786d6b0 by Ethan Furman in branch '2.7':
Issue24756: clarify usage of run_docstring_examples()
https://hg.python.org/cpython/rev/64d48786d6b0

New changeset ce595a047bd9 by Ethan Furman in branch '3.4':
Issue24756: clarify usage of run_docstring_examples()
https://hg.python.org/cpython/rev/ce595a047bd9

New changeset 767cc99020d2 by Ethan Furman in branch '3.5':
Issue24756: clarify usage of run_docstring_examples()
https://hg.python.org/cpython/rev/767cc99020d2

New changeset c8689d3df68a by Ethan Furman in branch 'default':
Close issue24756: clarify usage of run_docstring_examples()
https://hg.python.org/cpython/rev/c8689d3df68a
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68944
2015-09-18 05:22:52python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg250936

resolution: fixed
stage: patch review -> resolved
2015-07-31 22:51:59terry.reedysetnosy: + terry.reedy
messages: + msg247784
2015-07-30 13:36:54ethan.furmansetmessages: + msg247668
2015-07-30 13:34:00ethan.furmansetnosy: + ethan.furman
2015-07-30 13:27:10r.david.murraycreate