案例研究:用 Python 建構軟體
Mark Pedigo
Principal Data Scientist


doctest、pytestdoctest:驗證 docstring 範例def area(l, w):
"""
Finds the area given length and width and returns the result
>>> area(1, 1)
1
"""
return l + w
import doctest
doctest.testmod()
Failed example:
area(1,1)
Expected:
1
Got:
2
def area(l, w):
"""
Finds the area given length and width and returns the result
>>> area(1, 1)
1
"""
return l * w
import doctest
doctest.testmod()
一切正常=沒有錯誤訊息、沒有輸出
案例研究:用 Python 建構軟體