Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
codecov:
require_ci_to_pass: yes

coverage:
status:
project:
default:
target: 100%
threshold: 0%
patch:
default:
target: 100%

ignore:
- "tests/"
- "**/*test*.rs"

comment:
layout: "reach,diff,flags,tree"
behavior: default

# Exclude specific patterns from coverage
# coverage:off and coverage:on comments are recognized by CodeCov
7 changes: 2 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ jobs:
os: ["ubuntu"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
override: true
profile: minimal
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "foobar"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.23.3", features = ["extension-module"] }
pyo3 = { version = "0.23.5", features = ["extension-module"] }

[package.metadata.maturin]
python-source = "python"
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,15 @@ The last step of this process happens in the CI, where we upload both coverage
files to CodeCov. [Merging reports](https://docs.codecov.com/docs/merging-reports)
is an automatic feature of CodeCov, so the final view shows the combined view.

# Excluding code from coverage

The `#[pymodule]` initialization function in `src/lib.rs` is surrounded by
`LCOV_EXCL_START` and `LCOV_EXCL_STOP` [exclusion markers](https://manpages.ubuntu.com/manpages/noble/man5/lcovrc.5.html).
These markers instruct LCOV-compatible coverage tools to exclude the enclosed
region from coverage analysis. This is necessary because PyO3's module
initialization code is generated by a procedural macro and cannot be directly
tested in a way that produces coverage data (see [rust-lang/rust#84605](https://github.com/rust-lang/rust/issues/84605)).
The markers appear as comments in the source code and are recognized by CodeCov
when processing the LCOV report generated by `cargo-llvm-cov`.

https://codecov.io/gh/cjermain/rust-python-coverage
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"pytest>=8.3.4",
"pytest>=8.4.2",
"pytest-cov>=6.0.0",
"maturin>=1.8.1",
"maturin>=1.9.6",
]

[build-system]
requires = ["maturin>=1.0,<2.0"]
requires = ["maturin>=1.9,<2.0"]
build-backend = "maturin"

[tool.maturin]
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ fn pyo3_sum(a: usize, b: usize) -> PyResult<usize> {
}

/// A Python module implemented in Rust.
// LCOV_EXCL_START - PyO3 module initialization cannot be directly tested (see rust-lang/rust#84605)
#[pymodule]
fn _foobar(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(pyo3_sum, m)?)?;
Ok(())
}
// LCOV_EXCL_STOP

#[cfg(test)]
mod tests {
Expand Down
262 changes: 137 additions & 125 deletions uv.lock

Large diffs are not rendered by default.