Crate pyo3_testing

Source
Expand description

Simplifies testing of #[pyo3function]s by enabling tests to be condensed to:

# use pyo3_testing::pyo3test;
#[pyo3test]
#[pyo3import(py_adders: from adders import addone)]
fn test_pyo3test_simple_case() {
    let result: isize = addone!(1);
    assert_eq!(result, 2);
}

and for checking that the correct type of python Exception is raised:

# 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",)) });
}

Macros§

with_py_raises
A proc macro to implement the equivalent of pytest’s with raises context manager.

Attribute Macros§

pyo3test
A proc macro to decorate tests, which removes boilerplate code required for testing pyO3-wrapped functions within rust.