python 文档测试:doctest
2018-07-23 16:25
337 查看
doctest作用:会把文档中注释的代码提取并进行测试。
#!/usr/bin/python # -*- coding: utf-8 -*- class Dict(dict): ''' Simple dict but also support access as x.y style. >>> d1 = Dict() >>> d1['x'] = 100 >>> d1.x 100 >>> d1.y = 200 >>> d1['y'] 200 >>> d2 = Dict(a=1, b=2, c='3') >>> d2.c '3' >>> d2['empty'] Traceback (most recent call last): ... KeyError: 'empty' >>> d2.empty Traceback (most recent call last): ... AttributeError: 'Dict' object has no attribute 'empty' ''' def __init__(self, **kw): super(Dict, self).__init__(**kw) def __getattr__(self, key): try: return self[key] except KeyError: raise AttributeError(r"'Dict' object has no attribute '%s'" % key) def __setattr__(self, key, value): self[key] = value if __name__=='__main__': import doctest doctest.testmod()什么也没有输出,证明程序正确。
相关文章推荐
- Python的文档测试(doctest)
- 关于python测试的nose框架和doc test以及和junit的一点对比
- python 测试框架doctest
- Python 测试(一)—— doctest
- python doctest测试
- Python代码测试 - unitest\doctest\nose
- Python中的测试模块unittest和doctest的使用教程
- Python doctest自动测试
- python自动化单元测试工具----doctest
- python下常见的测试框架之二--doctest
- Python 测试之 doctest
- python中doctest自我测试(测试模块中的函数是否对)
- Python 各种测试框架简介(一):doctest
- python doctest测试框架
- Python代码测试 - unitest\doctest\nose
- Python测试框架doctest
- Python测试框架doctest
- python测试——doctest和unittest
- python测试框架doctest
- 【Python】Unittest,DDT,Selenium测试百度搜索