Skip to content

Commit 768b2bc

Browse files
Merge pull request #938 from microsoft/psl-add-coverage-pr-comment-v4
feat: Add pytest coverage comment to PRs
2 parents 0d2132a + 77b322b commit 768b2bc

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

.github/workflows/test.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ on:
3535
- 'src/**/pyproject.toml'
3636
- '.github/workflows/test.yml'
3737

38+
permissions:
39+
contents: read
40+
actions: read
41+
pull-requests: write
42+
3843
jobs:
3944
test:
4045
runs-on: ubuntu-latest
@@ -71,9 +76,9 @@ jobs:
7176
run: |
7277
# Run test_app.py first (isolation required)
7378
python -m pytest src/tests/backend/test_app.py --cov=src/backend --cov-config=.coveragerc -q
74-
79+
7580
# Run remaining backend tests with coverage append
76-
python -m pytest src/tests/backend --cov=src/backend --cov-append --cov-report=term --cov-report=xml --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py
81+
python -m pytest src/tests/backend --cov=src/backend --cov-append --cov-report=term --cov-report=xml --junitxml=pytest.xml --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py
7782
7883
- name: Check coverage threshold
7984
if: env.skip_tests == 'false'
@@ -91,7 +96,19 @@ jobs:
9196
exit 1
9297
fi
9398
99+
- name: Pytest Coverage Comment
100+
if: |
101+
always() &&
102+
github.event_name == 'pull_request' &&
103+
github.event.pull_request.head.repo.fork == false &&
104+
env.skip_tests == 'false'
105+
uses: MishaKav/pytest-coverage-comment@26f986d2599c288bb62f623d29c2da98609e9cd4 # v1.6.0
106+
with:
107+
pytest-xml-coverage-path: coverage.xml
108+
junitxml-path: pytest.xml
109+
report-only-changed-files: true
110+
94111
- name: Skip coverage report if no tests
95112
if: env.skip_tests == 'true'
96113
run: |
97-
echo "Skipping coverage report because no tests were found."
114+
echo "Skipping coverage report because no tests were found."

0 commit comments

Comments
 (0)