Skip to content

Commit b516121

Browse files
authored
Add code coverage to the tests (#75)
* feat(noxfile, pyproject): add coverage flags to pytest run Add flags for coverage reporting in pytest run. Modify pytest session to check for "--coverage" flag and extend PYTEST_RUN_FLAGS with PYTESTCOVERAGE_FLAGS if found. (issue: feature/codecov) * nox * fragment * upload-coverage copyright notice * ci: Update dependencies in workflow file (feature/codecov)
1 parent 10ecb64 commit b516121

7 files changed

Lines changed: 1486 additions & 5 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Added
2+
body: Code coverage tooling
3+
time: 2025-05-16T11:56:31.7775427+02:00
4+
custom:
5+
Author: rayakame
6+
PR: "75"

.coverage

96 KB
Binary file not shown.

.github/workflows/ci.yml

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,76 @@ jobs:
5555
# GitHub tells you which host‑port was assigned via the `job.services` context
5656
POSTGRES_URI: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports['5432'] }}/testdb
5757
run: |
58-
uv run nox -s pytest
58+
uv run nox -s pytest -- --coverage
59+
60+
- name: Upload coverage
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: .coverage.${{ matrix.python-version }}
64+
path: .coverage
65+
retention-days: 1
66+
if-no-files-found: error
67+
include-hidden-files: true
68+
69+
# upload-coverage taken from: https://github.com/hikari-py/hikari/blob/master/.github/workflows/ci.yml#L66
70+
#
71+
# Copyright (c) 2020 Nekokatt
72+
# Copyright (c) 2021-present davfsa
73+
#
74+
# Permission is hereby granted, free of charge, to any person obtaining a copy
75+
# of this software and associated documentation files (the "Software"), to deal
76+
# in the Software without restriction, including without limitation the rights
77+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78+
# copies of the Software, and to permit persons to whom the Software is
79+
# furnished to do so, subject to the following conditions:
80+
#
81+
# The above copyright notice and this permission notice shall be included in all
82+
# copies or substantial portions of the Software.
83+
upload-coverage:
84+
needs: [ test ]
85+
runs-on: ubuntu-latest
86+
87+
steps:
88+
- uses: actions/checkout@v4
89+
- name: Install uv
90+
uses: astral-sh/setup-uv@v6
91+
with:
92+
version: "0.6.9"
93+
python-version: "3.13"
94+
activate-environment: true
95+
96+
- name: Download coverage
97+
uses: actions/download-artifact@v4
98+
with:
99+
path: coverages/
100+
101+
- name: Extract individual coverage files
102+
run: |
103+
cd coverages
104+
105+
for coverage_dir in ./.coverage.*; do
106+
mv "$coverage_dir/.coverage" "../$coverage_dir"
107+
rmdir "$coverage_dir"
108+
done
109+
110+
cd ..
111+
112+
- name: Combine coverage
113+
run: |
114+
uv sync --frozen --only-group coverage
115+
116+
coverage combine
117+
coverage xml
118+
coverage report
119+
120+
- name: Upload coverage to codecov
121+
uses: codecov/codecov-action@v5
122+
with:
123+
token: ${{ secrets.CODECOV_TOKEN }}
124+
125+
126+
127+
59128

60129
ruff:
61130
runs-on: ubuntu-latest
@@ -105,7 +174,7 @@ jobs:
105174
uv run nox -s asyncpg_check
106175
107176
ci-done:
108-
needs: [ test, asyncpg, pyright, ruff ]
177+
needs: [ test,upload-coverage, asyncpg, pyright, ruff ]
109178
if: always() && !cancelled()
110179

111180
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)