-
Notifications
You must be signed in to change notification settings - Fork 28
72 lines (61 loc) · 2.52 KB
/
Copy pathpython-tests.yml
File metadata and controls
72 lines (61 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Python Tests
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
checks: write
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.12', '3.13' ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install pytest and pytest-cov
run: |
pip install pytest pytest-cov
# Run tests with continue-on-error so that coverage and PR comments are always published.
# The final step will explicitly fail the job if any test failed, ensuring PRs cannot be merged with failing tests.
- name: Run pytest with coverage and generate JUnit XML
run: |
PYTHONPATH=$(pwd) COVERAGE_FILE=tests/python/.coverage-${{ matrix.python-version }} pytest --cov=shared/python --cov-config=tests/python/.coveragerc --cov-report=html:tests/python/htmlcov-${{ matrix.python-version }} --junitxml=tests/python/junit-${{ matrix.python-version }}.xml tests/python/
continue-on-error: true
- name: Upload coverage HTML report
uses: actions/upload-artifact@v4
with:
name: coverage-html-${{ matrix.python-version }}
path: tests/python/htmlcov-${{ matrix.python-version }}/
- name: Upload JUnit test results
uses: actions/upload-artifact@v4
with:
name: junit-results-${{ matrix.python-version }}
path: tests/python/junit-${{ matrix.python-version }}.xml
- name: Publish Unit Test Results to PR
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: tests/python/junit-${{ matrix.python-version }}.xml
comment_title: Python ${{ matrix.python-version }} Test Results
# Explicitly fail the job if any test failed (so PRs cannot be merged with failing tests).
# This runs after all reporting steps, meaning coverage and PR comments are always published.
- name: Fail if tests failed
if: always()
run: |
if grep -q 'failures="[1-9]' tests/python/junit-${{ matrix.python-version }}.xml; then
echo "::error ::Unit tests failed. See above for details."
exit 1
fi