From b9c68c2f9bbe943de62295f09367027ec76a33d2 Mon Sep 17 00:00:00 2001 From: Peter Karalekas Date: Fri, 14 Aug 2020 11:47:37 -0400 Subject: [PATCH] Add Codecov for testing code coverage in the CI (#301) * Add coverage.xml to .gitignore * Generate XML coverage report when running Makefile test targets * Add codecov step to GitHub CI test job * Add link to Actions page to README build badge * Rename workflows so that their names are lowercase * Un-gitignore .coveragerc and add one * Add newline to end of .coveragerc * Only submit code coverage at the end of the py38 test job * Add codecov badge to the README --- .coveragerc | 3 +++ .github/workflows/ci-master.yml | 2 +- .github/workflows/ci.yml | 12 +++++++++--- .gitignore | 3 ++- Makefile | 8 ++++---- README.md | 3 ++- 6 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000000..658f13881c --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[run] +omit = + */tests/* diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml index 86a812dcb1..3bb6dbcf32 100644 --- a/.github/workflows/ci-master.yml +++ b/.github/workflows/ci-master.yml @@ -1,4 +1,4 @@ -name: Build (Master Only) +name: build (master only) on: push: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1225f59b5f..ff33ae0849 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Build +name: build on: pull_request: @@ -60,7 +60,7 @@ jobs: - name: Lint with flake8 run: make check-style - # runs all the unit tests (including pyQuil/Qiskit) on ubuntu and py36/37/38 + # runs all the unit tests (on Ubuntu, py36/37/38) and measures code coverage test: runs-on: ${{ matrix.os }} strategy: @@ -83,5 +83,11 @@ jobs: run: | docker run --rm -idt -p 5000:5000 rigetti/qvm -S docker run --rm -idt -p 5555:5555 rigetti/quilc -R - - name: Run all the unit tests via pytest + - name: Run all the unit tests & generate coverage report with pytest run: make test-all + - name: Submit coverage report to Codecov + # only submit to Codecov once + if: ${{ matrix.python-version == 3.8 }} + uses: codecov/codecov-action@v1.0.12 + with: + fail_ci_if_error: true diff --git a/.gitignore b/.gitignore index 92b53b4246..b750babb9a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .vscode .python-version .idea/ -.coverage* +.coverage *.dat *.ipynp *.ipynb_checkpoints @@ -12,3 +12,4 @@ docs/build/ mitiq.egg-info/ dist/ build/ +coverage.xml diff --git a/Makefile b/Makefile index 3d5cf69b10..b8c2da47bc 100644 --- a/Makefile +++ b/Makefile @@ -44,16 +44,16 @@ requirements: requirements.txt .PHONY: test test: - pytest -v --cov=mitiq mitiq/tests mitiq/benchmarks/tests + pytest -v --cov=mitiq --cov-report=term --cov-report=xml mitiq/tests mitiq/benchmarks/tests .PHONY: test-pyquil test-pyquil: - pytest -v --cov=mitiq mitiq/mitiq_pyquil/tests + pytest -v --cov=mitiq --cov-report=term --cov-report=xml mitiq/mitiq_pyquil/tests .PHONY: test-qiskit test-qiskit: - pytest -v --cov=mitiq mitiq/mitiq_qiskit/tests + pytest -v --cov=mitiq --cov-report=term --cov-report=xml mitiq/mitiq_qiskit/tests .PHONY: test-all test-all: - pytest --cov=mitiq + pytest --cov=mitiq --cov-report=term --cov-report=xml diff --git a/README.md b/README.md index 998d9eb600..a70d822f67 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -![Python Build](https://github.com/unitaryfund/mitiq/workflows/Python%20Build/badge.svg?branch=master) +[![build](https://github.com/unitaryfund/mitiq/workflows/build/badge.svg)](https://github.com/unitaryfund/mitiq/actions) +[![codecov](https://codecov.io/gh/unitaryfund/mitiq/branch/master/graph/badge.svg)](https://codecov.io/gh/unitaryfund/mitiq) [![PyPI version](https://badge.fury.io/py/mitiq.svg)](https://badge.fury.io/py/mitiq) [![Unitary Fund](https://img.shields.io/badge/Supported%20By-UNITARY%20FUND-brightgreen.svg?style=for-the-badge)](http://unitary.fund)