Skip to content

Commit 711587e

Browse files
Store the code coverage files on each test run for CI. (#2245)
* Store the code coverage files on each test run for CI. Allow the COVERAGE_FILE environment variable to be passed through tox. * Use relative files to support properly merging coverage files.
1 parent c02105b commit 711587e

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

.github/workflows/test.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ jobs:
7575
DB_PASSWORD: debug_toolbar
7676
DB_HOST: 127.0.0.1
7777
DB_PORT: 3306
78+
COVERAGE_FILE: ".coverage.mysql.${{ matrix.python-version }}"
79+
80+
- name: Store coverage file
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: coverage-mysql-${{ matrix.python-version }}
84+
path: .coverage.mysql.${{ matrix.python-version }}*
85+
include-hidden-files: true
7886

7987

8088
postgres:
@@ -169,6 +177,14 @@ jobs:
169177
DB_HOST: localhost
170178
DB_PORT: 5432
171179
DJANGO_SELENIUM_TESTS: ${{ matrix.env.DJANGO_SELENIUM_TESTS }}
180+
COVERAGE_FILE: ".coverage.${{ matrix.database }}.${{ matrix.python-version }}"
181+
182+
- name: Store coverage file
183+
uses: actions/upload-artifact@v4
184+
with:
185+
name: coverage-${{ matrix.database }}-${{ matrix.python-version }}
186+
path: .coverage.${{ matrix.database }}.${{ matrix.python-version }}*
187+
include-hidden-files: true
172188

173189
sqlite:
174190
runs-on: ubuntu-latest
@@ -214,6 +230,14 @@ jobs:
214230
env:
215231
DB_BACKEND: sqlite3
216232
DB_NAME: ":memory:"
233+
COVERAGE_FILE: ".coverage.sqlite.${{ matrix.python-version }}"
234+
235+
- name: Store coverage file
236+
uses: actions/upload-artifact@v4
237+
with:
238+
name: coverage-sqlite-${{ matrix.python-version }}
239+
path: .coverage.sqlite.${{ matrix.python-version }}*
240+
include-hidden-files: true
217241

218242
lint:
219243
runs-on: ubuntu-latest
@@ -252,3 +276,38 @@ jobs:
252276
253277
- name: Test with tox
254278
run: tox -e docs,packaging
279+
280+
coverage:
281+
name: Coverage
282+
runs-on: ubuntu-latest
283+
needs:
284+
- mysql
285+
- postgres
286+
- sqlite
287+
permissions:
288+
pull-requests: write
289+
contents: write
290+
steps:
291+
- uses: actions/checkout@v4
292+
with:
293+
persist-credentials: false
294+
295+
- uses: actions/download-artifact@v4
296+
id: download
297+
with:
298+
pattern: coverage-*
299+
merge-multiple: true
300+
301+
- name: Coverage comment
302+
id: coverage_comment
303+
uses: py-cov-action/python-coverage-comment-action@6494290850a5098c2836298dad8f11082b4ceaa9 # v3
304+
with:
305+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
306+
MERGE_COVERAGE_FILES: true
307+
308+
- name: Store Pull Request comment to be posted
309+
uses: actions/upload-artifact@v4
310+
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
311+
with:
312+
name: python-coverage-comment-action
313+
path: python-coverage-comment-action.txt

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Pending
66

77
* Deprecated ``RedirectsPanel`` in favor of ``HistoryPanel`` for viewing
88
toolbar data from redirected requests.
9+
* Fixed support for generating code coverage comments in PRs.
910

1011
6.1.0 (2025-10-30)
1112
------------------

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ skip_empty = true
9999
[tool.coverage.run]
100100
branch = true
101101
parallel = true
102+
relative_files = true
102103
source = [
103104
"debug_toolbar",
104105
]

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ deps =
3131
passenv=
3232
CI
3333
COVERAGE_ARGS
34+
COVERAGE_FILE
3435
DB_BACKEND
3536
DB_NAME
3637
DB_USER

0 commit comments

Comments
 (0)