Skip to content

Commit 8d3ef6a

Browse files
authored
Add coverage commenting (#48)
* Add coverage commenting - Issues with codecov (number of available seats) when collaborating, switching to a PR commenter that provides coverage info (https://github.com/MishaKav/pytest-coverage-comment) - Combine XML files as needed
1 parent c5b8aaa commit 8d3ef6a

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/test.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Python Tests
22

33
permissions:
44
contents: read
5+
pull-requests: write
56

67
on:
78
push:
@@ -72,10 +73,30 @@ jobs:
7273
-m "full_pipeline" \
7374
--runner=docker \
7475
--junitxml=pytest-full.xml \
76+
--cov-report=xml:coverage.xml \
7577
--cov=src tests \
7678
--cov-append \
7779
--verbose
7880
81+
- name: Generate combined coverage report
82+
if: matrix.os == 'ubuntu-latest'
83+
shell: bash
84+
run: >
85+
uv run coverage xml -o coverage.xml
86+
87+
- name: Merge JUnitXml files
88+
if: matrix.os == 'ubuntu-latest'
89+
shell: bash
90+
run: >
91+
uv run scripts/merge_cov_junitxml.py
92+
93+
- name: Pytest coverage comment
94+
if: matrix.os == 'ubuntu-latest'
95+
uses: MishaKav/pytest-coverage-comment@v1
96+
with:
97+
pytest-xml-coverage-path: ./coverage.xml
98+
junitxml-path: ./pytest.xml
99+
79100
ruff:
80101
runs-on: ubuntu-latest
81102
steps:

scripts/merge_cov_junitxml.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# /// script
2+
# dependencies = ["junitparser"]
3+
# requires-python = ">=3.12"
4+
# ///
5+
"""Merge pytest-cov's junitxml file for codecov commenting.
6+
7+
Reads all generated junitxml files and generates:
8+
- pytest.xml (merged xml file)
9+
10+
Run with:
11+
uv run scripts/merge_cov_junitxml.py
12+
"""
13+
14+
from pathlib import Path
15+
16+
from junitparser import JUnitXml
17+
18+
19+
def main() -> None:
20+
"""Merge generated junitxml files."""
21+
merged = JUnitXml()
22+
for f in ["pytest-quick.xml", "pytest-slow.xml", "pytest-full.xml"]:
23+
if Path(f).exists():
24+
merged += JUnitXml.fromfile(f)
25+
merged.write("pytest.xml")
26+
27+
28+
if __name__ == "__main__":
29+
main()

0 commit comments

Comments
 (0)