ComeçarComece de graça

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 exercício faz parte do curso

Case Study: Building Software in Python

Ver curso

Exercício interativo prático

Transforme a teoria em ação com um de nossos exercícios interativos

Começar o exercício