[Python-checkins] cpython (merge 3.5 -> default): Close issue24756: clarify usage of run_docstring_examples()

ethan.furman python-checkins at python.org
Fri Sep 18 07:22:50 CEST 2015


https://hg.python.org/cpython/rev/c8689d3df68a
changeset: 98027:c8689d3df68a
parent: 98023:b77916d2d7cc
parent: 98026:767cc99020d2
user: Ethan Furman <ethan at stoneleaf.us>
date: Thu Sep 17 22:22:20 2015 -0700
summary:
 Close issue24756: clarify usage of run_docstring_examples()
files:
 Doc/library/doctest.rst | 30 ++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -914,15 +914,10 @@
 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.
 
@@ -1815,6 +1810,27 @@
 * 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.
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /