Skip to content

Commit a37df54

Browse files
authored
enable code coverage collection and reporting INFERENG-1049 (#382)
* enable collection of code coverage metrics during test execution * upload coversage results as run artifact * debugging env var use * we don't use uv in this repo * point coverage to correct package! * name package with underscore instead of hyphen * helpful debug statement showing PYTEST_ADDOPTS * debugging print statements * looking for coverage files * found coverage generated files. removing debugging statements
1 parent 6c63987 commit a37df54

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

.github/actions/test/action.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
suitename:
88
description: "test suite name"
99
required: true
10+
code_coverage:
11+
description: whether to collect code coverage metrics during test run
12+
type: boolean
13+
default: false
1014
outputs:
1115
status:
1216
description: "final status from test"
@@ -44,9 +48,37 @@ runs:
4448
run: |
4549
source ${{ inputs.venv }}/bin/activate
4650
rm -rf src
51+
52+
if [[ "${ENABLE_COVERAGE}" == "true" ]]; then
53+
echo "::group::Installing code coverage requirements via pip"
54+
pip install bashlex https://github.com/neuralmagic/pytest-nm-releng/archive/v0.4.0.tar.gz
55+
pip install coverage pytest-cov
56+
57+
# Adding Code coverage to the tests
58+
nmre-generate-coverage-flags --package "compressed_tensors" --output-file ".coverage_flags.sh"
59+
source .coverage_flags.sh
60+
echo "::endgroup::"
61+
fi
62+
63+
echo "::group::running tests"
64+
echo "PYTEST_ADDOPTS set to: ${PYTEST_ADDOPTS}"
65+
4766
SUCCESS=0
4867
pytest tests --junitxml=test-results/report.xml -o junit_suite_name="${{ inputs.suitename }}" || SUCCESS=$?
4968
echo "status=${SUCCESS}" >> "$GITHUB_OUTPUT"
69+
echo "::endgroup::"
70+
71+
if [[ "${ENABLE_COVERAGE}" == "true" ]]; then
72+
echo "::group::consolidating coverage reports"
73+
mkdir -p coverage-results
74+
mv .coverage coverage-results/ || echo ".coverage file not found"
75+
mv coverage-html coverage-results/ || echo "coverage-html folder not found"
76+
mv coverage.json coverage-results/ || echo "coverage.json file not found"
77+
echo "::endgroup::"
78+
fi
79+
5080
deactivate
5181
exit ${SUCCESS}
5282
shell: bash
83+
env:
84+
ENABLE_COVERAGE: ${{ inputs.code_coverage || false }}

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ on:
2525
run_id:
2626
description: run id of the BUILD job that generated the assets
2727
type: string
28+
code_coverage:
29+
description: whether to collect code coverage metrics during test run
30+
type: boolean
31+
default: false
2832

2933
# makes workflow manually callable
3034
workflow_dispatch:
@@ -51,6 +55,10 @@ on:
5155
run_id:
5256
description: run id of the BUILD job that generated the assets
5357
type: string
58+
code_coverage:
59+
description: whether to collect code coverage metrics during test run
60+
type: boolean
61+
default: false
5462

5563
jobs:
5664

@@ -124,6 +132,7 @@ jobs:
124132
with:
125133
venv: ${{ steps.create_venv.outputs.penv }}
126134
suitename: test-${{ inputs.python }}-${{ inputs.test_label }}
135+
code_coverage: ${{ inputs.code_coverage }}
127136

128137
- name: summary
129138
uses: neuralmagic/nm-actions/actions/summary-test@v1.13.0
@@ -146,3 +155,11 @@ jobs:
146155
name: report-${{ inputs.test_label }}.xml
147156
path: test-results/report.xml
148157
retention-days: 5
158+
159+
- name: upload coverage report
160+
uses: actions/upload-artifact@v4
161+
if: (success() || failure()) && inputs.code_coverage
162+
with:
163+
name: coverage-results
164+
path: coverage-results/*
165+
retention-days: 5

0 commit comments

Comments
 (0)