def report_failure(self, out, test, example, got):
raise DocTestFailure(test, example, got)
######################################################################
## 6. Test Functions
######################################################################
# These should be backwards compatible.
# For backward compatibility, a global instance of a DocTestRunner
# class, updated by testmod.
python类testmod()的实例源码
def run_docstring_examples(f, globs, verbose=False, name="NoName",
compileflags=None, optionflags=0):
"""
Test examples in the given object's docstring (`f`), using `globs`
as globals. Optional argument `name` is used in failure messages.
If the optional argument `verbose` is true, then generate output
even if there are no failures.
`compileflags` gives the set of flags that should be used by the
Python compiler when running the examples. If not specified, then
it will default to the set of future-import flags that apply to
`globs`.
Optional keyword arg `optionflags` specifies options for the
testing and output. See the documentation for `testmod` for more
information.
"""
# Find, parse, and run all tests in the given module.
finder = DocTestFinder(verbose=verbose, recurse=False)
runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
for test in finder.find(f, name, globs=globs):
runner.run(test, compileflags=compileflags)
######################################################################
## 7. Tester
######################################################################
# This is provided only for backwards compatibility. It's not
# actually used in any way.
def _test():
import doctest
doctest.testmod()
def _test():
import doctest
doctest.testmod()
def _test():
import doctest
return doctest.testmod()
def _test():
import doctest
doctest.testmod()
def _test():
import doctest, stripxml
doctest.testmod(stripxml)
def test_local():
failures, _ = doctest.testmod(local, report=True)
assert failures == 0
def test_ondisk():
if has_special_dependencies:
failures, _ = doctest.testmod(ondisk, report=True)
assert failures == 0
def test_s3():
failures, _ = doctest.testmod(s3, report=True)
assert failures == 0
def test_caching():
failures, _ = doctest.testmod(caching, report=True)
assert failures == 0
def test_docs_pythonapi_creating_archives(example_snippet_working_dirs):
failures, _ = doctest.testmod(pythonapi_creating_archives, report=True)
assert failures == 0
def test_docs_pythonapi_tagging(example_snippet_working_dirs):
failures, _ = doctest.testmod(pythonapi_tagging, report=True)
assert failures == 0
def test_docs_pythonapi_dependencies(example_snippet_working_dirs):
failures, _ = doctest.testmod(pythonapi_dependencies, report=True)
assert failures == 0
def test_docs_pythonapi_io(example_snippet_working_dirs):
if has_special_dependencies:
failures, _ = doctest.testmod(pythonapi_io, report=True)
assert failures == 0
def test_docs_pythonapi_metadata(example_snippet_working_dirs):
failures, _ = doctest.testmod(pythonapi_metadata, report=True)
assert failures == 0
def test_docs_pythonapi_finding_archives(example_snippet_working_dirs):
failures, _ = doctest.testmod(pythonapi_finding_archives, report=True)
assert failures == 0
def _test():
import doctest, os, sys
sys.path.insert(0, os.pardir)
import pytz
return doctest.testmod(pytz)
def test():
import doctest
doctest.testmod()
def testModule(name):
print "--- Test module %s" % name
module = importModule(name)
failure, nb_test = testmod(module)
if failure:
exit(1)
print "--- End of test"