From a2b62ff60a6bda97a7505b1f4dc9cb436a7566a7 Mon Sep 17 00:00:00 2001 From: Fabien MARTY Date: Wed, 31 May 2023 16:14:22 +0200 Subject: [PATCH] add codecov --- .coveragerc | 2 ++ .github/workflows/lint.yaml | 7 ++++++- dev-requirements.txt | 4 ++++ tasks.py | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..1dc549e --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +omit = fnv_c/ext/build.py diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d2a4d60..70b36fe 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -35,7 +35,7 @@ jobs: invoke lint --no-fix - name: Run tests run: | - invoke test + invoke test --coverage - name: Make API docs if: matrix.python-version == '3.7' run: | @@ -46,6 +46,11 @@ jobs: with: name: apidoc path: apihtml/ + - name: Upload coverage reports to Codecov + if: matrix.python-version == '3.7' && github.ref == 'refs/heads/main' && github.event_name == 'push' + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} githubpages: runs-on: ubuntu-latest diff --git a/dev-requirements.txt b/dev-requirements.txt index f7f56cd..b529d82 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,6 +4,7 @@ certifi==2023.5.7 cffi==1.15.1 charset-normalizer==3.1.0 click==8.1.3 +coverage==7.2.7 docutils==0.20.1 dunamai==1.17.0 idna==3.4 @@ -28,6 +29,9 @@ pluggy==1.0.0 pycparser==2.21 Pygments==2.15.1 pytest==7.3.1 +pytest-cov==4.1.0 +pytest-cover==3.0.0 +pytest-coverage==0.0 readme-renderer==37.3 requests==2.31.0 requests-toolbelt==1.0.0 diff --git a/tasks.py b/tasks.py index 88470f1..fcf8d26 100644 --- a/tasks.py +++ b/tasks.py @@ -10,6 +10,10 @@ def _clean_apidoc(c): c.run("rm -Rf apihtml") +def _clean_coverage(c): + c.run("rm -Rf htmlcov") + + @task def clean(c): """Clean the repository""" @@ -18,6 +22,7 @@ def clean(c): c.run("find . -type d -name __pycache__ -exec rm -Rf {} \\; 2>/dev/null || true") c.run("rm -Rf dist build") _clean_apidoc(c) + _clean_coverage(c) @task(help={"fix": "try to automatically fix the code (default)"}) @@ -45,10 +50,16 @@ def lint(c, fix=True): lint_black(c, fix=fix) -@task() +@task(help={"coverage": "compute coverage"}) def test(c, coverage=False): """Execute unit tests""" - c.run("pytest .") + if coverage: + _clean_coverage(c) + c.run( + f"pytest --cov-config=.coveragerc --no-cov-on-fail --cov={PACKAGE} --cov-report=term --cov-report=html --cov-report=xml ." + ) + else: + c.run("pytest .") @task