From fd967f94cdf25dcac47abe075aaa14b918d28a77 Mon Sep 17 00:00:00 2001 From: Amanda Zhu Date: Fri, 9 May 2025 16:42:40 +1000 Subject: [PATCH 1/9] add code coverage and badge --- .github/workflows/python-tests.yml | 15 +++++++++++---- README.md | 2 ++ pyproject.toml | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 4b599662..5ada67cf 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -1,4 +1,4 @@ -name: Run Pytest +name: Run Pytest with Coverage on: push: @@ -35,8 +35,15 @@ jobs: - name: Create virtual environment and install dependencies run: | uv venv - uv sync + uv sync --dev # Include dev tools like pytest and pytest-cov - - name: Run tests + - name: Run tests with coverage run: | - uv run pytest + uv run pytest --cov=aai_backend --cov-report=xml --cov-report=term + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} # Optional for public repos + files: ./coverage.xml + fail_ci_if_error: true diff --git a/README.md b/README.md index 20a22204..a7b5b7d7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # AAI Backend +[![codecov](https://codecov.io/gh/AustralianBioCommons/aai-backend/branch/main/graph/badge.svg)](https://codecov.io/gh/AustralianBioCommons/aai-backend) + The backend library between Auth0 and the AAI portal front end. Technical design document for this project lives in [this Google doc](https://docs.google.com/document/d/1W3-7Hme08M-b4kwMvcQoUscznVNxtOldxuKYPPRhBFE/edit?tab=t.0). ## Requirements diff --git a/pyproject.toml b/pyproject.toml index 661ef26d..2a5c024a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,4 +20,5 @@ dev = [ "polyfactory>=2.21.0", "pytest>=8.3.5", "pytest-mock>=3.14.0", + "pytest-cov>=4.1.0", ] From f37ae04d2b70d3205b46ee6057917ae39e0e841b Mon Sep 17 00:00:00 2001 From: Amanda Zhu Date: Fri, 9 May 2025 16:51:28 +1000 Subject: [PATCH 2/9] use irongut/CodeCoverageSummary --- .github/workflows/python-tests.yml | 16 +++++++++++----- README.md | 2 -- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 5ada67cf..f39550a9 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -41,9 +41,15 @@ jobs: run: | uv run pytest --cov=aai_backend --cov-report=xml --cov-report=term - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + - name: Code Coverage Report + uses: irongut/CodeCoverageSummary@v1.3.0 with: - token: ${{ secrets.CODECOV_TOKEN }} # Optional for public repos - files: ./coverage.xml - fail_ci_if_error: true + filename: coverage/cobertura.xml + badge: true + fail_below_min: true + format: markdown + hide_branch_rate: true + hide_complexity: true + indicators: true + output: console + thresholds: '90 90' \ No newline at end of file diff --git a/README.md b/README.md index a7b5b7d7..20a22204 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # AAI Backend -[![codecov](https://codecov.io/gh/AustralianBioCommons/aai-backend/branch/main/graph/badge.svg)](https://codecov.io/gh/AustralianBioCommons/aai-backend) - The backend library between Auth0 and the AAI portal front end. Technical design document for this project lives in [this Google doc](https://docs.google.com/document/d/1W3-7Hme08M-b4kwMvcQoUscznVNxtOldxuKYPPRhBFE/edit?tab=t.0). ## Requirements From 53da822e85a15dadb406c80f480c349cbbaf053b Mon Sep 17 00:00:00 2001 From: Amanda Zhu Date: Fri, 9 May 2025 17:18:37 +1000 Subject: [PATCH 3/9] fix report generation --- .github/workflows/python-tests.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index f39550a9..4c8b15a8 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -37,9 +37,13 @@ jobs: uv venv uv sync --dev # Include dev tools like pytest and pytest-cov - - name: Run tests with coverage + - name: Run tests and generate Cobertura coverage report run: | - uv run pytest --cov=aai_backend --cov-report=xml --cov-report=term + mkdir -p coverage + uv run pytest --cov=aai_backend \ + --cov-report=term-missing \ + --cov-report=xml:coverage/cobertura.xml \ + --cov-fail-under=90 \ - name: Code Coverage Report uses: irongut/CodeCoverageSummary@v1.3.0 From 943b4763a91fc560030879a62e27460989d9d01b Mon Sep 17 00:00:00 2001 From: Amanda Zhu Date: Fri, 9 May 2025 17:25:20 +1000 Subject: [PATCH 4/9] fix run tests --- .github/workflows/python-tests.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 4c8b15a8..30e49355 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -40,10 +40,11 @@ jobs: - name: Run tests and generate Cobertura coverage report run: | mkdir -p coverage - uv run pytest --cov=aai_backend \ - --cov-report=term-missing \ - --cov-report=xml:coverage/cobertura.xml \ - --cov-fail-under=90 \ + PYTHONPATH=./ uv run pytest \ + --cov=aai_backend \ + --cov-report=term-missing \ + --cov-report=xml:coverage/cobertura.xml \ + --cov-fail-under=90 \ - name: Code Coverage Report uses: irongut/CodeCoverageSummary@v1.3.0 From bb84d251bb6a45e832d1cf267a374f54175722f5 Mon Sep 17 00:00:00 2001 From: Amanda Zhu Date: Fri, 9 May 2025 17:49:13 +1000 Subject: [PATCH 5/9] make CI happy --- .github/workflows/python-tests.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 30e49355..a81dea41 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -40,11 +40,15 @@ jobs: - name: Run tests and generate Cobertura coverage report run: | mkdir -p coverage - PYTHONPATH=./ uv run pytest \ - --cov=aai_backend \ + PYTHONPATH=. uv run pytest \ + --cov=auth \ + --cov=schemas \ + --cov=routers \ + --cov=main \ --cov-report=term-missing \ --cov-report=xml:coverage/cobertura.xml \ --cov-fail-under=90 \ + --cov-report=html:coverage/html - name: Code Coverage Report uses: irongut/CodeCoverageSummary@v1.3.0 From 18ae22eb8e50ec8b8571ffd5ac07512bd780af09 Mon Sep 17 00:00:00 2001 From: Amanda Zhu Date: Sat, 10 May 2025 16:30:51 +1000 Subject: [PATCH 6/9] fix coverage to 80% --- .github/workflows/python-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index a81dea41..d9ba5e68 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -61,4 +61,4 @@ jobs: hide_complexity: true indicators: true output: console - thresholds: '90 90' \ No newline at end of file + thresholds: '80 80' \ No newline at end of file From e119d48540e6d23fcf8cca0c1b8e327c968a44d0 Mon Sep 17 00:00:00 2001 From: Amanda Zhu Date: Sat, 10 May 2025 16:33:39 +1000 Subject: [PATCH 7/9] fix cov-fail-under to 80% --- .github/workflows/python-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index d9ba5e68..f2354d90 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -47,7 +47,7 @@ jobs: --cov=main \ --cov-report=term-missing \ --cov-report=xml:coverage/cobertura.xml \ - --cov-fail-under=90 \ + --cov-fail-under=80 \ --cov-report=html:coverage/html - name: Code Coverage Report From b78501c007e96d1ca4a2481c52cf14de5c3f8d3e Mon Sep 17 00:00:00 2001 From: marius-mather Date: Tue, 13 May 2025 16:04:01 +1000 Subject: [PATCH 8/9] Add coveragerc to ignore tests dir by default --- .coveragerc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..c712d259 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +omit = tests/* From cd15a529632d7c2efb9a677e93e3d0e49bc8ec62 Mon Sep 17 00:00:00 2001 From: marius-mather Date: Tue, 13 May 2025 16:07:19 +1000 Subject: [PATCH 9/9] Include everything in coverage --- .github/workflows/python-tests.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index f2354d90..81372125 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -41,10 +41,7 @@ jobs: run: | mkdir -p coverage PYTHONPATH=. uv run pytest \ - --cov=auth \ - --cov=schemas \ - --cov=routers \ - --cov=main \ + --cov \ --cov-report=term-missing \ --cov-report=xml:coverage/cobertura.xml \ --cov-fail-under=80 \