From b33f9f9b66e120d5a50797aa3f3847a5514e4214 Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Tue, 27 Aug 2024 20:57:14 +0200 Subject: [PATCH] Measure test coverage with Codecov (#62) * feat: Measure test coverage with Codecov * fix: Add Codecov configuration --- .github/workflows/backend-python.yaml | 16 +++++++++++++++- .github/workflows/client-python.yaml | 16 +++++++++++++++- backend/pyproject.toml | 2 +- backend/requirements-dev.txt | 5 +++++ backend/tests/__init__.py | 0 backend/tests/integration/__init__.py | 0 backend/tests/unit/__init__.py | 0 client/pyproject.toml | 2 +- client/requirements-dev.txt | 6 ++++++ client/requirements.txt | 2 -- codecov.yml | 11 +++++++++++ 11 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 backend/tests/__init__.py create mode 100644 backend/tests/integration/__init__.py create mode 100644 backend/tests/unit/__init__.py create mode 100644 codecov.yml diff --git a/.github/workflows/backend-python.yaml b/.github/workflows/backend-python.yaml index c36e36f4..871b64b1 100644 --- a/.github/workflows/backend-python.yaml +++ b/.github/workflows/backend-python.yaml @@ -7,6 +7,7 @@ on: pull_request: paths: - backend/** + - .github/** branches: - main @@ -47,4 +48,17 @@ jobs: - name: Execute python tests run: | uv pip install . # need to install without --no-deps to work around non-portable dependency resolution in `uv pip compile` - pytest + uv run pytest -s --cov=src --cov-report=xml --junitxml=junit.xml + - name: Upload results to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./backend/coverage.xml + slug: aai-institute/infrastructure-product + flags: backend + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./backend/junit.xml diff --git a/.github/workflows/client-python.yaml b/.github/workflows/client-python.yaml index b814aa19..083c53fd 100644 --- a/.github/workflows/client-python.yaml +++ b/.github/workflows/client-python.yaml @@ -7,6 +7,7 @@ on: pull_request: paths: - client/** + - .github/** branches: - main @@ -47,4 +48,17 @@ jobs: - name: Execute python tests run: | uv pip install . # need to install without --no-deps to work around non-portable dependency resolution in `uv pip compile` - pytest + pytest --cov=src --cov-report=xml --junitxml=junit.xml + - name: Upload results to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./client/coverage.xml + slug: aai-institute/infrastructure-product + flags: client + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./client/junit.xml diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 37aa1f04..58f6c232 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ ] [project.optional-dependencies] -dev = ["build", "ruff", "pytest", "pytest-mock", "pre-commit", "testcontainers"] +dev = ["build", "ruff", "pytest", "pytest-mock", "pytest-cov", "pre-commit", "testcontainers"] # Automatically determine version number from Git tags [tool.setuptools_scm] diff --git a/backend/requirements-dev.txt b/backend/requirements-dev.txt index f7e5297b..24e959d9 100644 --- a/backend/requirements-dev.txt +++ b/backend/requirements-dev.txt @@ -52,6 +52,8 @@ click==8.1.7 # uvicorn colorful==0.5.6 # via ray +coverage==7.6.1 + # via pytest-cov distlib==0.3.8 # via virtualenv dnspython==2.6.1 @@ -247,7 +249,10 @@ pyproject-hooks==1.1.0 pytest==8.3.2 # via # jobs-server (pyproject.toml) + # pytest-cov # pytest-mock +pytest-cov==5.0.0 + # via jobs-server (pyproject.toml) pytest-mock==3.14.0 # via jobs-server (pyproject.toml) python-dateutil==2.9.0.post0 diff --git a/backend/tests/__init__.py b/backend/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/tests/integration/__init__.py b/backend/tests/integration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/tests/unit/__init__.py b/backend/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/client/pyproject.toml b/client/pyproject.toml index a8854abd..ca3083c5 100644 --- a/client/pyproject.toml +++ b/client/pyproject.toml @@ -28,7 +28,7 @@ jobs_execute = "jobs.execute:execute" jobby = "jobs.cli:main" [project.optional-dependencies] -dev = ["build", "ruff", "pytest", "pre-commit"] +dev = ["build", "ruff", "pytest", "pytest-cov", "pre-commit"] docs = [ "mkdocs", "mkdocs-callouts", diff --git a/client/requirements-dev.txt b/client/requirements-dev.txt index dcf176a1..6f9d2da5 100644 --- a/client/requirements-dev.txt +++ b/client/requirements-dev.txt @@ -54,6 +54,8 @@ colorama==0.4.6 # mkdocs-material colorful==0.5.6 # via ray +coverage==7.6.1 + # via pytest-cov distlib==0.3.8 # via virtualenv docker==7.1.0 @@ -304,6 +306,10 @@ pyparsing==3.1.2 pyproject-hooks==1.1.0 # via build pytest==8.2.2 + # via + # job-queue (pyproject.toml) + # pytest-cov +pytest-cov==5.0.0 # via job-queue (pyproject.toml) python-dateutil==2.9.0.post0 # via diff --git a/client/requirements.txt b/client/requirements.txt index 0ebcf9fb..ee87ae17 100644 --- a/client/requirements.txt +++ b/client/requirements.txt @@ -243,8 +243,6 @@ tensorboardx==2.6.2.2 # via ray tensorflow==2.16.1 # via job-queue (pyproject.toml) -tensorflow-io-gcs-filesystem==0.36.0 - # via tensorflow termcolor==2.4.0 # via tensorflow textual==0.72.0 diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..8e4229e8 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,11 @@ +ignore: + - "test_*.py" + - "**/tests/**" +flag_management: + individual_flags: + - name: client + paths: + - "client/" + - name: backend + paths: + - "backend/"