1. 学ぶ
  2. /
  3. プロジェクト
  4. /
  5. ケーススタディ:Pythonでソフトウェアを構築する

Connected

演習

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 Shell のため先頭に ! が必要です。たとえば !pytest file_name.py のように実行します。

指示

50 XP

選択肢