使用 pytest 測試程式碼
請看 test.py 中的以下測試程式碼。
def test_mortgage_calculator_example():
'''
Test an example case for the mortgage calculator
'''
# Instantiate a mortgage calculator
mortgage_calculator = calculators.MortgageCalculator(200000,
0.065,
30)
# Calculate the monthly payment
monthly_payment = mortgage_calculator.monthly_payment
# Run a test
assert monthly_payment == 1264.14
如果用 pytest 檢查這個檔案,會通過嗎?請注意,在主控台使用 Pytest 時,需要在前面加上 !,例如 !pytest file_name.py,因為這是 IPython Shell。
本練習屬於課程
