原理和语言

The Python Standard Library - De

2019-07-30  本文已影响0人  左心Chris

3 doctest

3.0 Intro

  1. 为了最新测试module’s docstrings are up-to-date
  2. 为了回归测试regression testing by verifying that interactive examples from a test file or a test object work as expected
  3. 为了写指南文档To write tutorial documentation for a package, liberally illustrated with input-output examples.
    官方samples:https://github.com/python/cpython/blob/3.7/Lib/test/test_doctest.py

3.1 Simple Usage in Docstrings

# module M
if __name__ == "__main__":
    import doctest
    doctest.testmod()
python M.py # only fail
python M.py -v # all(verbose)

doctest then examines docstrings in module M.

3.2 Simple Usage in a Text File

import doctest
doctest.testfile("example.txt")
上一篇下一篇

猜你喜欢

热点阅读