시작하기무료로 시작하기

pytest로 코드 테스트하기

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

이 파일을 pytest로 검사하면 통과할까요? 콘솔에서 Pytest를 사용하려면 IPython 셸 환경이므로 !로 시작해야 합니다. 예: !pytest file_name.py.

이 연습은 강의의 일부입니다

케이스 스터디: Python으로 소프트웨어 만들기

강의 보기

실습형 인터랙티브 연습문제

이론을 실습으로 바꾸는 인터랙티브 연습 중 하나를 만나보세요

연습 시작