#author("2018-10-08T09:26:22+00:00","","") * pytest入門 [#e9ffd5bd] #setlinebreak(on); #contents ** インストール [#q4177cd9] #html(<div style="padding-left:10px;">) #myterm2(){{ pip install pytest pip install pytest-cov }} #html(</div>) ** フォルダ構成 [#f0395e6c] #html(<div style="padding-left:10px;">) tests ├── __init__.py └── sample ├── __init__.py |── conftest.py # セットアップコードを記述 └── test_code.py # テストケースを記述 #html(</div>) ** テストコードの基本系 [#kcb84353] #html(<div style="padding-left:10px;">) #html(</div>) ** セットアップコードの書き方 [#q5d6c439] #html(<div style="padding-left:10px;">) #html(</div>) ** xxxxxxxxxxx [#jeb0588f] #html(<div style="padding-left:10px;">) https://qiita.com/mitamura_kei/items/e51c604155633ccd33dd setup処理からparameterを引き渡したい テストケースごとに固有の前後処理をしたい @pytest.fixture #html(</div>) ** fixtureを使いこなす [#i35963cf] ** Tips [#me3d48f1] *** 標準出力に表示する [#o9a2ab13] pytest -s *** 処理時間を計測する [#ic092ee4] テスト時間を記録したい pytest --durations=0 pytest -v --duration=0 *** 前処理と後処理 [#zc0f5637] @pytest.fixture *** 同じテストを値を変えて行う [#gfdb5035] @pytest.mark.parametrize *** テストをグループ化する [#sc0ef4e4] @pytest.mark テストケース別に結果を表示する pytest -v 前回NGだったケースだけテストする pytest -v --lf 前回NGだったケースからテストする pytest -v --ff 遅いテストケースを見つける pytest -v --duration=5 テストログをテキストファイルに出力する pytest -v --result-log=tests/log.txt カバレッジ計測 https://qiita.com/kg1/items/e2fc65e4189faf50bfe6 コマンドラインでカバレッジを確認 pytest -v --cov=ディレクトリ コマンドラインで網羅できなかったコード行を知りたい pytest -v --cov=ディレクトリ --cov-report=term-missing HTML形式のカバレッジレポートを出力する pytest -v --cov=ディレクトリ --cov-report=html