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.
This exercise is part of the course
Case Study: Building Software in Python
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
