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.
Este ejercicio forma parte del curso
Case Study: Building Software in Python
Ejercicio interactivo práctico
Pon en práctica la teoría con uno de nuestros ejercicios interactivos
Empezar ejercicio