Crates.io | pyo3-testing |
lib.rs | pyo3-testing |
version | 0.3.5 |
source | src |
created_at | 2024-05-23 20:53:41.942435 |
updated_at | 2024-06-28 15:29:52.547428 |
description | Simplified testing for pyo3-wrapped functions |
homepage | https://github.com/MusicalNinjas/pyo3-testing |
repository | https://github.com/MusicalNinjas/pyo3-testing |
max_upload_size | |
id | 1250274 |
size | 50,340 |
Pyo3-testing is designed to save the need to continually build and install your wrapped extension modules in order to run integration tests in python.
It provides a test attribute #[pyo3test]
which allows you to shorten your tests to:
#[pyo3test]
#[pyo3import(py_adders: from adders import addone)]
fn test_pyo3test_simple_case() {
let result: isize = addone!(1);
assert_eq!(result, 2);
}
Without pyo3-testing
this test can run to over 20 lines of code and randomly fail due to issues with python interpreter pre-initialisation.
It also provides a with_py_raises!
macro modelled on pytest's with raises
context manager to test for expected Exceptions:
# use pyo3_testing::{pyo3test, with_py_raises};
#[pyo3test]
#[allow(unused_macros)]
#[pyo3import(py_adders: from adders import addone)]
fn test_raises() {
with_py_raises!(PyTypeError, { addone.call1(("4",)) });
}
For a walk-through guide to using the crate along with lots of other tips on developing rust extensions for python see: Combining rust & python - a worked example
Technical documentation for the crate is available at docs.rs
This crate wouldn't be possible or necessary without the amazing work done by pyo3
... are very welcome via MusicalNinjas/pyo3-testing