Skip to content

Commit

Permalink
Issue24756: clarify usage of run_docstring_examples()
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfurman committed Sep 18, 2015
2 parents 8e3b04c + 2a5f9da commit 7b51a55
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Doc/library/doctest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,10 @@ and :ref:`doctest-simple-testfile`.
above, except that *globs* defaults to ``m.__dict__``.


There's also a function to run the doctests associated with a single object.
This function is provided for backward compatibility. There are no plans to
deprecate it, but it's rarely useful:


.. function:: run_docstring_examples(f, globs, verbose=False, name="NoName", compileflags=None, optionflags=0)

Test examples associated with object *f*; for example, *f* may be a module,
function, or class object.
Test examples associated with object *f*; for example, *f* may be a string,
a module, a function, or a class object.

A shallow copy of dictionary argument *globs* is used for the execution context.

Expand Down Expand Up @@ -1815,6 +1810,27 @@ several options for organizing tests:
* Define a ``__test__`` dictionary mapping from regression test topics to
docstrings containing test cases.

When you have placed your tests in a module, the module can itself be the test
runner. When a test fails, you can arrange for your test runner to re-run only
the failing doctest while you debug the problem. Here is a minimal example of
such a test runner::

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))


.. rubric:: Footnotes

.. [#] Examples containing both expected output and an exception are not supported.
Expand Down

0 comments on commit 7b51a55

Please sign in to comment.