From 0744cfae9531a5c4eefa6c6c9503b19c7abe0487 Mon Sep 17 00:00:00 2001 From: Stefano Braghin <527806+stefano81@users.noreply.github.com> Date: Mon, 31 Aug 2026 11:00:56 +0100 Subject: [PATCH] feat: add code coverage test Signed-off-by: Stefano Braghin <527806+stefano81@users.noreply.github.com> --- .github/workflows/testing.yml | 26 ++++++++++++++++++++++++-- codecov.yml | 23 +++++++++++++++++++++++ pyproject.toml | 16 +++++++++++++++- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 codecov.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8df6f4a..4c9514e 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -114,7 +114,6 @@ jobs: - name: Install dependencies run: | uv sync --all-extras - uv pip install pytest-cov - name: Download spaCy models run: | @@ -130,5 +129,28 @@ jobs: uv run python -m nltk.downloader words - name: Run tests with coverage + # --cov-fail-under enforces the overall regression floor (configured in + # pyproject.toml [tool.coverage.report] fail_under = 33). + # Patch coverage (new/changed lines ≥ 80%) is enforced by Codecov below. run: | - uv run pytest tests/ --cov=src/risk_assessment --cov-report=xml --cov-report=html --cov-report=term + uv run pytest tests/ \ + --cov=src/risk_assessment \ + --cov-report=xml \ + --cov-report=html \ + --cov-report=term-missing + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.xml + fail_ci_if_error: true + verbose: true + + - name: Upload HTML coverage report as artifact + uses: actions/upload-artifact@v4 + if: always() + with: + name: coverage-html-report + path: htmlcov/ + retention-days: 14 diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..6e43d84 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,23 @@ +coverage: + status: + project: + # Overall coverage must not drop below the current baseline. + # `target: auto` means "don't regress from the last commit on the base branch". + # The 1% threshold gives a small float to absorb measurement noise. + default: + target: auto + threshold: 1% + informational: false # fails the PR check if breached + + patch: + # Lines added or changed by the PR must be covered at ≥ 80%. + default: + target: 80% + threshold: 0% + informational: false # fails the PR check if breached + +comment: + layout: "reach,diff,flags,files" + behavior: default # updates the existing comment on re-push + require_changes: true # only post when coverage actually changes + hide_project_coverage: false diff --git a/pyproject.toml b/pyproject.toml index c407660..a8d3d61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -165,4 +165,18 @@ include = ["src", "tests"] exclude = [".pre-commit-config.yaml"] [tool.pytest.ini_options] -addopts = "--cov=risk_assessment --cov-report html" +addopts = "--cov=src/risk_assessment --cov-report=html --cov-report=xml --cov-report=term-missing" + +[tool.coverage.run] +source = ["src/risk_assessment"] +omit = [ + "*/tests/*", + "*/__init__.py", +] + +[tool.coverage.report] +# Regress guard: overall coverage must not drop below this. +# Update this value when coverage genuinely improves. +fail_under = 33 +show_missing = true +skip_covered = false