The Python Standard Library - Development Tools

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")
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 7,998评论 0 3
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,199评论 0 10
  • 远见是精神上的导航仪,只要在导航仪输入你的“当前位置”和“目标”便能快速到达你想到的彼岸。远见和信念是相...
    红豆_dd47阅读 1,418评论 0 0
  • 词:林夕唱:郑秀文 塔尖仍旧记得 这拥抱极美好爱有千斤重 重过无涯的铁路你那手指再笨拙再粗 肌肤也被你修补从...
    六尺帐篷阅读 3,712评论 0 1
  • 华东师大版本 复旦陈纪修版
    吴康建阅读 10,784评论 0 3

友情链接更多精彩内容