您的位置:首页 > 编程语言 > Python开发

python doctest模块学习笔记

2011-12-11 22:11 113 查看
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,可以是多行的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: