Test the code using pytest
Consider the following test code in 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
Will this file pass if you check it using pytest? Note that in order to use Pytest in the console you will need to start with !, e.g., !pytest file_name.py, because it is an IPython Shell.
Cet exercice fait partie du cours
Case Study: Building Software in Python
Exercice interactif pratique
Passez de la théorie à la pratique avec l’un de nos exercices interactifs
Commencer l’exercice