Skip to content

Commit f374d8e

Browse files
committed
feat(COVERPORT-22): add codecov integration for test coverage
Add pytest-cov, configure GitHub Actions to upload coverage with unit-tests flag. Signed-off-by: daturece <daturece@redhat.com>
1 parent 0609bc7 commit f374d8e

File tree

4 files changed

+176
-2
lines changed

4 files changed

+176
-2
lines changed

.github/workflows/python.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: Python Checks for Pull Requests
33
on:
4+
push:
5+
branches:
6+
- main
47
pull_request:
58
types:
69
- opened
@@ -27,9 +30,16 @@ jobs:
2730
python-version: "3.9" # Same as in Dockerfile
2831
- name: flake8 Lint
2932
uses: py-actions/flake8@84ec6726560b6d5bd68f2a5bed83d62b52bb50ba # v2
30-
- name: Run pytest
33+
- name: Run pytest with coverage
3134
run: |
3235
curl -LsSf https://astral.sh/uv/install.sh | sh
3336
export PATH="$HOME/.local/bin:$PATH"
3437
uv sync --dev
35-
uv run pytest
38+
uv run pytest --cov=. --cov-report=xml:coverage.xml
39+
- name: Upload coverage to Codecov
40+
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}
43+
flags: unit-tests
44+
files: coverage.xml
45+
fail_ci_if_error: false

codecov.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
4+
coverage:
5+
precision: 2
6+
round: down
7+
range: "50...100"
8+
9+
flags:
10+
unit-tests:
11+
carryforward: true
12+
13+
comment:
14+
layout: "reach,diff,flags,files"
15+
behavior: default

pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,19 @@ line-length = 95
2828
dev = [
2929
"black>=25.11.0",
3030
"pytest>=8.4.2",
31+
"pytest-cov>=6.0",
3132
]
33+
34+
[tool.coverage.run]
35+
omit = [
36+
"**/test_*",
37+
"**/tests/*",
38+
".github/*",
39+
"ci/*",
40+
"scripts/*",
41+
"templates/*",
42+
"data/*",
43+
]
44+
45+
[tool.coverage.report]
46+
show_missing = true

0 commit comments

Comments
 (0)