python doctest模块学习笔记

You can force verbose mode by passing verbose=True to testmod()不用在 python x.py -v后面加-v显示测试打印信息



The module docstring, and all function, class and method docstrings are searched. Objects imported into the module are not searched.

检查模块,函数,方法,类的docstrings。导入的模块不检查。

如果模块定义__test__会检查,测试里面定义的项


 How are Docstring Examples Recognized?:

大多数情况下哦复制粘贴IDLE中的会话(seesion)即可。但python不会去尝试特制的仿真器。

Any expected output must immediately follow the final '>>> ' or '... ' line containing the code, and the expected output (if any) extends to the next '>>> ' or all-whitespace line.
所有期待的输出必须紧跟包含代码的'>>>'或者'...'。输出后面紧跟'>>> ' 或者空格。
Expected output cannot contain an all-whitespace line, since such a line is taken to signal the end of expected output. If expected output does contain a blank line, put <BLANKLINE> in your doctest example each place a blank line is expected.
输出不能是全空白行,如果有这样的输出用<BLANKLINE> 代替。
All hard tab characters are expanded to spaces, using 8-column tab stops. Tabs in output generated by the tested code are not modified.
所有硬编码的Tab被展开成8列的空格符,测试代码产生的Tab不会被修改。

25.2.3.3. What’s the Execution Context?

doctest在测试时复制被测试module的globals
你可以在测试代码中用module的变量。但不能用别的docstring的变量。
输出exception时开头要:
Traceback (most recent call last):
Traceback (innermost last):

中间被忽略

后面跟eccp的详细信息NameError: name 'a' is not defined,可以是多行的。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值