pip install pytest pip install pytest-cov
tests
├── __init__.py
└── sample
├── __init__.py |── conftest.py # セットアップコードを記述 └── test_code.py # テストケースを記述
https://qiita.com/mitamura_kei/items/e51c604155633ccd33dd
setup処理からparameterを引き渡したい
テストケースごとに固有の前後処理をしたい
@pytest.fixture
pytest -s
テスト時間を記録したい
pytest --durations=0
pytest -v --duration=0
@pytest.fixture
@pytest.mark.parametrize
@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