monarch-initiative / semsimian

Simple rust implementation of semantic similarity
BSD 3-Clause "New" or "Revised" License
8 stars 5 forks source link

Set up test coverage compatible with PyO3 #59

Closed caufieldjh closed 1 year ago

caufieldjh commented 1 year ago

@iQuxLE and I looked at https://github.com/cjermain/rust-python-coverage in an attempt to get test coverage calculation working in a way that works with PyO3 (cargo-tarpaulin consistently produced verbose errors seemingly related to PyO3).

Here's what worked (for me, at least):

$ cargo install cargo-llvm-cov
$ cargo llvm-cov show-env --export-prefix
$ cargo llvm-cov clean --workspace
$ cargo test
$ cargo llvm-cov --lcov --output-path coverage.lcov
$ sudo apt install lcov # if necessary, as this is what installs genhtml
$ genhtml -o output-dir coverage.lcov

This will run the rust tests and generate coverage reports in output-dir. Including python tests should just require:

$ maturin develop
$ pytest tests --cov=foobar --cov-report xml
justaddcoffee commented 1 year ago

Excellent @caufieldjh! This worked like a charm for me too and it also seems to avoid that weird thing @iQuxLE was observing where lib.rs was counted as having several thousand lines of code (?)

Screen Shot 2023-05-31 at 11 27 46 AM
caufieldjh commented 1 year ago

Great, it works on M1 too then. Will try to incorporate into the workflow as part of #55

caufieldjh commented 1 year ago

Note that the pytest cov report needs pip install pytest-cov

caufieldjh commented 1 year ago

Done in #55