Skip to content

Commit d540a6e

Browse files
authored
Add test coverage to CI workflow (#2690)
* Add test coverage to workflow * Add diff_cover package * Update worklow * Update CONTRIBUTING.md
1 parent fd5ba93 commit d540a6e

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

.github/workflows/python-test.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
node_version: ["20.14", "22"]
3030
steps:
3131
- uses: actions/checkout@v5
32+
with:
33+
# Fetch full history so diff-cover can compute a merge base with origin/main
34+
fetch-depth: 0
3235
- name: Install uv
3336
uses: astral-sh/setup-uv@v6
3437
with:
@@ -61,7 +64,14 @@ jobs:
6164
run: black . --check --verbose
6265
- name: Run Python tests
6366
if: runner.os != 'Windows'
64-
run: pytest -s -vv --cov --cov-fail-under=89
67+
run: pytest -s -vv --cov --cov-report=xml --cov-fail-under=89
68+
- name: Check diff coverage
69+
if: runner.os != 'Windows'
70+
run: |
71+
BASE_REF="${{ github.base_ref }}"
72+
if [ -z "$BASE_REF" ]; then BASE_REF="main"; fi
73+
git fetch origin "$BASE_REF:refs/remotes/origin/$BASE_REF"
74+
diff-cover coverage.xml --compare-branch="origin/$BASE_REF" --fail-under=90
6575
- name: Run E2E tests with Playwright
6676
id: e2e
6777
if: runner.os != 'Windows'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ coverage.xml
5454
.hypothesis/
5555
.pytest_cache/
5656
cover/
57+
coverage_report.html
5758

5859
# Translations
5960
*.mo

CONTRIBUTING.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ contact [[email protected]](mailto:[email protected]) with any additio
1717
- [Running unit tests](#running-unit-tests)
1818
- [Running E2E tests](#running-e2e-tests)
1919
- [Code style](#code-style)
20-
- [Adding new azd environment variables](#adding-new-azd-environment-variables)
21-
- [Adding new UI strings](#adding-new-ui-strings)
20+
- [Adding new features](#adding-new-features)
21+
- [Adding new azd environment variables](#adding-new-azd-environment-variables)
22+
- [Adding new UI strings](#adding-new-ui-strings)
2223

2324
## Submitting a Pull Request (PR)
2425

@@ -62,10 +63,18 @@ Run the tests:
6263
python -m pytest
6364
```
6465

65-
Check the coverage report to make sure your changes are covered.
66+
If test snapshots need updating (and the changes are expected), you can update them by running:
6667

6768
```shell
68-
python -m pytest --cov
69+
python -m pytest --snapshot-update
70+
```
71+
72+
Once tests are passing, generate a coverage report to make sure your changes are covered:
73+
74+
```shell
75+
pytest --cov --cov-report=xml && \
76+
diff-cover coverage.xml --format html:coverage_report.html && \
77+
open coverage_report.html
6978
```
7079

7180
## Running E2E tests
@@ -118,7 +127,15 @@ python -m black <path-to-file>
118127

119128
If you followed the steps above to install the pre-commit hooks, then you can just wait for those hooks to run `ruff` and `black` for you.
120129

121-
## Adding new azd environment variables
130+
## Adding new features
131+
132+
We recommend using GitHub Copilot Agent mode when adding new features,
133+
as this project includes [.github/copilot-instructions.md](.github/copilot-instructions.md) file
134+
that instructs Copilot on how to generate code for common code changes.
135+
136+
If you are not using Copilot Agent mode, consult both that file and suggestions below.
137+
138+
### Adding new azd environment variables
122139

123140
When adding new azd environment variables, please remember to update:
124141

@@ -128,7 +145,7 @@ When adding new azd environment variables, please remember to update:
128145
1. [ADO pipeline](.azdo/pipelines/azure-dev.yml).
129146
1. [Github workflows](.github/workflows/azure-dev.yml)
130147

131-
## Adding new UI strings
148+
### Adding new UI strings
132149

133150
When adding new UI strings, please remember to update all translations.
134151
For any translations that you generate with an AI tool,

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ pytest-snapshot
1212
pre-commit
1313
pip-tools
1414
mypy==1.14.1
15+
diff_cover
1516
axe-playwright-python

0 commit comments

Comments
 (0)