LoginSignup
2
0

More than 3 years have passed since last update.

CircleCIからpytestのカバレッジ結果を見る

Last updated at Posted at 2020-04-16

概要

テストカバレッジのレポートをHTMLとして出したけどCircleCIから見る方法がわからない!

という方向けに、どうすればカバレッジレポートをCircleCIから見る方法を書いていきます

注意

結構強引なので、もっといいやり方がある気がします。何かいい方法を知っている方はコメントでお願いします

手順

  1. カバレッジレポートを出す
  2. config.ymlを変更してArtifactsとしてアクセスできるようにする

カバレッジレポートを出す

どう出してもかまいませんが、ここはpytestでやっていこうと思います(楽なので)

srcディレクトリのコードについて、test-reportsディレクトリにHTML形式のカバレッジレポートを出します

pytest --cov=src --cov-report=html:test-reports

config.ymlをいじる

version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.7.2
    steps:
      (省略)
      - run:
          name: run test
          command: |
            . venv/bin/activate
            pip install pytest
            pip install pytest-cov
            pytest --cov=src --cov-report=html:test-reports
      - store_artifacts:
          path: test-reports/
          destination: circleci-docs

のようにすると、以下の画像のようにArtifactsの部分にカバレッジレポートのファイル群が表示されます

image.png

これのindex.htmlを踏むと、カバレッジレポートが見れました!やった

ファイル名をクリックすると、きちんとファイルごとの結果についても見れます

終わりです

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0