Skip to content

Commit 2ae407c

Browse files
Include gpu and example tests also in codecov coverage reporting and enable omitted folder coverage (#1154)
So far, we only measured unit test coverage but we also have gpu test and example tests which needed to be setup differently to track in overall codecov coverage so we get accurate coverage reporting <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Strengthened code coverage measurement with parallelized collection across unit, GPU, and example test suites * Enhanced continuous integration workflow configuration with improved coverage reporting and threshold management * Updated testing infrastructure dependencies and settings to support more robust quality assurance processes <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
1 parent 09b3c0b commit 2ae407c

File tree

6 files changed

+60
-26
lines changed

6 files changed

+60
-26
lines changed

.github/codecov.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# Allow atmost 5% coverage drop from main branch.
1+
# Flags partition coverage by test suite. carryforward ensures that if GPU tests are skipped
2+
# on a PR (no relevant file changes), their coverage from the last nightly run is reused so
3+
# the comparison is not penalized for the missing upload.
4+
flag_management:
5+
default_rules:
6+
carryforward: true
27
coverage:
38
status:
49
project:
510
default:
611
target: auto
7-
threshold: 5%
12+
threshold: 2% # Allow atmost 2% coverage drop from main branch.
813
patch: false

.github/workflows/_example_tests_runner.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ jobs:
6161
6262
find examples/${{ inputs.example }} -name "requirements.txt" | while read req_file; do python -m pip install -r "$req_file" || exit 1; done
6363
- name: Run tests
64+
env:
65+
# Absolute paths so subprocesses running from different working directories
66+
# all find the config and write .coverage.* files to the same location.
67+
COVERAGE_PROCESS_START: ${{ github.workspace }}/pyproject.toml
68+
COVERAGE_FILE: ${{ github.workspace }}/.coverage
6469
run: |
6570
echo "Running tests for: ${{ inputs.example }}"
66-
pytest tests/examples/${{ inputs.example }}
71+
pytest tests/examples/${{ inputs.example }} --cov
72+
- name: Upload coverage to Codecov
73+
uses: codecov/codecov-action@v5
74+
with:
75+
token: ${{ secrets.CODECOV_TOKEN }}
76+
files: coverage.xml
77+
flags: examples
78+
fail_ci_if_error: false # test may be skipped if relevant file changes are not detected
79+
verbose: true

.github/workflows/gpu_tests.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,20 @@ jobs:
8686
run: |
8787
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/include:/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV
8888
- name: Run gpu tests
89-
run: pip install tox-current-env && tox -e cuda13-${{ matrix.example }} --current-env
89+
env:
90+
COVERAGE_PROCESS_START: ${{ github.workspace }}/pyproject.toml
91+
COVERAGE_FILE: ${{ github.workspace }}/.coverage
92+
run: |
93+
pip install tox-current-env
94+
COV_ARGS="--cov" tox -e cuda13-${{ matrix.example }} --current-env
95+
- name: Upload GPU coverage to Codecov
96+
uses: codecov/codecov-action@v5
97+
with:
98+
token: ${{ secrets.CODECOV_TOKEN }}
99+
files: coverage.xml
100+
flags: gpu
101+
fail_ci_if_error: false # test may be skipped if relevant file changes are not detected
102+
verbose: true
90103
gpu-tests-non-pr:
91104
if: ${{ !startsWith(github.ref, 'refs/heads/pull-request/') }}
92105
strategy: *gpu_strategy

.github/workflows/unit_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
uses: codecov/codecov-action@v5
4444
with:
4545
token: ${{ secrets.CODECOV_TOKEN }}
46+
flags: unit
4647
fail_ci_if_error: true
4748
verbose: true
4849
windows:

pyproject.toml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ dev-docs = [
101101
"sphinx-togglebutton>=0.3.2",
102102
]
103103
dev-test = [
104+
"coverage[toml]>=7.13.0", # a1_coverage.pth for subprocess tracking requires this
104105
"pytest",
105106
"pytest-cov",
106107
"pytest-instafail",
@@ -132,7 +133,7 @@ managed = true
132133

133134

134135
####################################################################################################
135-
############################### LINTING, FORMATTING AND TESTING CONFIGURATION ####################
136+
############################### LINTING, FORMATTING CONFIGURATION ################################
136137
####################################################################################################
137138
[tool.ruff]
138139
target-version = "py310"
@@ -256,6 +257,22 @@ ignore_errors = true
256257
module = ["examples.*"]
257258
disable_error_code = ["attr-defined"]
258259

260+
[tool.bandit]
261+
exclude_dirs = [".github/", "examples/", "tests/"]
262+
# Do not change `skips`. It should be consistent with NVIDIA's Wheel-CI-CD bandit.yml config.
263+
# Use of `# nosec BXXX` requires special approval
264+
skips = [
265+
"B101", # assert_used
266+
"B110", # try_except_pass
267+
"B112", # try_except_continue
268+
"B303", # MD2, MD4, MD5, or SHA1
269+
"B311", # random
270+
]
271+
272+
273+
####################################################################################################
274+
############################### TESTING CONFIGURATION ############################################
275+
####################################################################################################
259276
[tool.pytest.ini_options]
260277
# Default additional options
261278
# Show a short test summary info for all except passed tests with -ra flag
@@ -270,12 +287,12 @@ markers = [
270287

271288
[tool.coverage.run]
272289
branch = false
273-
include = ["modelopt/*"]
274-
omit = ["*/plugins/*", "*/export/*"]
290+
parallel = true
291+
concurrency = ["multiprocessing", "thread"]
292+
source_pkgs = ["modelopt", "modelopt_recipes"]
275293

276294

277295
[tool.coverage.report]
278-
fail_under = 70
279296
skip_covered = true
280297
ignore_errors = true
281298
exclude_lines = [
@@ -297,16 +314,3 @@ exclude_lines = [
297314
# Don't complain about abstract methods, they aren't run
298315
"@(abc\\.)?abstractmethod",
299316
]
300-
301-
302-
[tool.bandit]
303-
exclude_dirs = [".github/", "examples/", "tests/"]
304-
# Do not change `skips`. It should be consistent with NVIDIA's Wheel-CI-CD bandit.yml config.
305-
# Use of `# nosec BXXX` requires special approval
306-
skips = [
307-
"B101", # assert_used
308-
"B110", # try_except_pass
309-
"B112", # try_except_continue
310-
"B303", # MD2, MD4, MD5, or SHA1
311-
"B311", # random
312-
]

tox.ini

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ commands_pre =
6767
pip uninstall -y cupy-cuda12x
6868
pip install cupy-cuda13x
6969
commands =
70-
# Coverage fails with "Can't combine line data with arc data" error so not using "--cov"
71-
python -m pytest tests/gpu
70+
python -m pytest tests/gpu {env:COV_ARGS:}
7271

7372
[testenv:cuda13-gpu-megatron]
7473
commands_pre =
@@ -78,16 +77,15 @@ commands_pre =
7877
pip install --no-build-isolation git+https://github.com/Dao-AILab/causal-conv1d.git
7978
pip install -e .[hf,dev-test]
8079
commands =
81-
# Coverage fails with "Can't combine line data with arc data" error so not using "--cov"
82-
python -m pytest tests/gpu_megatron
80+
python -m pytest tests/gpu_megatron {env:COV_ARGS:}
8381

8482
[testenv:cuda13-gpu-trtllm]
8583
# Expected to be run in TRT-LLM container
8684
commands_pre =
8785
# Install deps here so that it gets installed even in --current-env
8886
pip install -e .[hf,dev-test]
8987
commands =
90-
python -m pytest tests/gpu_trtllm
88+
python -m pytest tests/gpu_trtllm {env:COV_ARGS:}
9189

9290
#############################################
9391
# Code quality checks on all files or on diff

0 commit comments

Comments
 (0)