Skip to content

Commit e2e4b51

Browse files
Enable coverage tracking
- Only run coverage on one platform (Cython line tracing seems to have some issues with Python 3.13, to be determined) - There are a few paradoxical red spots in the Cython coverage analysis (code that must run for other blocks to be green, but nevertheless showing up as red) but the analysis does give a good indication of where the blind spots are already.
1 parent f63a59a commit e2e4b51

6 files changed

Lines changed: 202 additions & 2 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Coverage
2+
on:
3+
push:
4+
branches: ["**"]
5+
pull_request: {}
6+
workflow_dispatch: {}
7+
env:
8+
UV_PYTHON_PREFERENCE: only-system
9+
UV_NO_SYNC: "1"
10+
jobs:
11+
# For now, we run the coverage as a separate job.
12+
# At the time of writing, the latest version of Cython's line tracing
13+
# seems to lead to segfaults in Python 3.13 -> TODO: investigate
14+
pytest-coverage:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Acquire sources
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: 3.12
24+
- uses: ./.github/actions/install-softhsm
25+
with:
26+
os: ubuntu-latest
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v4
29+
with:
30+
enable-cache: true
31+
python-version: 3.12
32+
- name: Install testing dependencies
33+
run: uv sync --no-dev --exact --group coverage
34+
env:
35+
CFLAGS: "-DCYTHON_TRACE_NOGIL=1"
36+
EXT_BUILD_DEBUG: "1"
37+
- name: Run tests
38+
run: uv run pytest -v --cov=pkcs11 --cov-branch --cov-report=xml:python-coverage.xml
39+
- name: Stash coverage report
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: coverage
43+
path: "*-coverage.xml"
44+
codecov-upload:
45+
permissions:
46+
actions: write
47+
contents: read
48+
runs-on: ubuntu-latest
49+
needs: [pytest-coverage]
50+
steps:
51+
# checkout necessary to ensure the uploaded report contains the correct paths
52+
- uses: actions/checkout@v4
53+
- name: Retrieve coverage reports
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: coverage
57+
path: ./reports/
58+
- name: Upload all coverage reports to Codecov
59+
uses: codecov/codecov-action@v5
60+
with:
61+
token: ${{ secrets.CODECOV_TOKEN }}
62+
directory: ./reports/
63+
flags: unittests
64+
env_vars: OS,PYTHON
65+
name: codecov-umbrella

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ __pycache__
66
/dist/
77
/docs/_build
88
/python_pkcs11.egg-info/
9-
/.eggs/
9+
/.eggs/
10+
.coverage
11+
*coverage.xml
12+
*.html

pkcs11/_pkcs11.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Definitions imported from PKCS11 C headers.
44

55
from cython.view cimport array
66

7-
from pkcs11.defaults import *
87
from pkcs11.exceptions import *
98

109
cdef extern from '../extern/cryptoki.h':

pkcs11/_pkcs11.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!python
22
#cython: language_level=3
3+
#cython: linetrace=True
34
"""
45
High-level Python PKCS#11 Wrapper.
56

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,35 @@ archs = ["universal2"]
6767
[tool.setuptools.packages.find]
6868
include = ["pkcs11*"]
6969

70+
[tool.coverage.run]
71+
plugins = ["Cython.Coverage"]
72+
73+
[tool.coverage.report]
74+
exclude_lines = [
75+
"pragma: no cover",
76+
"pragma: nocover",
77+
"raise AssertionError",
78+
"raise NotImplementedError",
79+
"raise MemoryError",
80+
"raise TypeError",
81+
"TYPE_CHECKING",
82+
"^\\s*\\.\\.\\.",
83+
"noqa"
84+
]
85+
precision = 2
86+
7087
[dependency-groups]
7188
testing = [
7289
"cryptography>=44.0.0",
7390
"parameterized>=0.9.0",
7491
"pytest>=8.3.4",
7592
]
93+
coverage = [
94+
{ include-group = "testing" },
95+
"coverage>=7.9.1",
96+
"pytest-cov>=4.0,<6.3",
97+
"cython",
98+
]
7699
docs = [
77100
"sphinx>=7.4.7",
78101
"sphinx-rtd-theme>=3.0.2",

0 commit comments

Comments
 (0)