GitHub Actions で pytest のカバレッジを出力する¶
MishaKav/pytest-coverage-commentの action を使うと、pytest で計測したカバレッジを GitHub の Pull Request や Job の Summary に出力できる。例は 2 通りある。
PR のコメントにカバレッジを出力する¶
次のワークフローは、mainブランチを指定した pytest-coverage-comment の action を使って、pytest を実行してカバレッジを計測し、結果を PR のコメントに出力する。
上のワークフローを実行した結果、PR には次のようなコメントが付いた。
Coverage Report
File Stmts Miss Cover Missing functions/example_completed example_completed.py 64 19 70% 33, 39–45, 48–51, 55–58, 65–70, 91–92 functions/example_manager example_manager.py 44 11 75% 31–33, 49–55, 67–69 example_static.py 40 2 95% 60–61 functions/my_exampels example.py 20 20 0% 1–31 functions/resources resources.py 26 26 0% 1–37 TOTAL 1055 739 30%
Job の Summary にカバレッジを出力する¶
PR にコメントを残したくない場合は、hide-comment: trueを指定するとコメントを止められる。代わりにactions/github-scriptを使えば、カバレッジの結果を Job の Summary へ追記できる。