案例研究:用 Python 构建软件
Mark Pedigo
Principal Data Scientist


doctest、pytestdoctest:验证文档字符串示例def area(l, w):
"""
根据长度和宽度计算面积并返回结果
>>> area(1, 1)
1
"""
return l + w
import doctest
doctest.testmod()
失败的示例:
area(1,1)
期望:
1
得到:
2
def area(l, w):
"""
根据长度和宽度计算面积并返回结果
>>> area(1, 1)
1
"""
return l * w
import doctest
doctest.testmod()
一切正常 = 无错误信息、无输出
案例研究:用 Python 构建软件