IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Case Study: Building Software in Python

Visualizza il corso

Esercizio pratico interattivo

Passa dalla teoria alla pratica con uno dei nostri esercizi interattivi

Inizia esercizio