From 0b228761b405c172aab7f6c247dbe2a6e2f1dcdb Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Wed, 7 May 2025 22:28:06 +0200 Subject: [PATCH] feat(backend): record contexts for coverage (#9643) * feat(backend): Record contexts for coverage * add docs --- .github/workflows/qc_checks.yaml | 6 ++++++ docs/docs/develop/contributing.md | 9 +++++++++ pyproject.toml | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index 1e5700213c..dfed724f5f 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -342,6 +342,12 @@ jobs: run: python3 .github/scripts/check_migration_files.py - name: Coverage Tests run: invoke dev.test --coverage --translations + - name: Upload raw coverage to artifacts + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2 + with: + name: coverage + path: .coverage + retention-days: 14 - name: Upload coverage reports to Codecov uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # pin@v5.4.2 if: always() diff --git a/docs/docs/develop/contributing.md b/docs/docs/develop/contributing.md index f1d3c4f975..6019ea4272 100644 --- a/docs/docs/develop/contributing.md +++ b/docs/docs/develop/contributing.md @@ -199,6 +199,15 @@ alter user myuser createdb; !!! info "Devcontainer" The default database container which is provided in the devcontainer is already setup with the required permissions +### Trace coverage to specific tests + +Sometimes it is valuable to get insights how many tests cover a specific statement and which ones do. coverage.py calls this information contexts. Contexts are automatically captured by the invoke task test (with coverage enabled) and can be rendered with below command into a HTML report. +```bash +coverage html -i +``` + +The coverage database is also generated in the CI-pipeline and exposd for 14 days as a artifact named `coverage`. + ## Code Style Code style is automatically checked as part of the project's CI pipeline on GitHub. This means that any pull requests which do not conform to the style guidelines will fail CI checks. diff --git a/pyproject.toml b/pyproject.toml index 5b0945f688..69176dbccf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,6 +102,10 @@ generate-hashes=true [tool.coverage.run] source = ["src/backend/InvenTree", "InvenTree"] +dynamic_context = "test_function" + +[tool.coverage.html] +show_contexts = true [tool.djlint] ignore = "D018,H006,H008,H020,H021,H023,H025,H030,H031,T002"