Skip to main content

Crate pyo3_testing

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

§Supported pyo3 version(s)

As of v0.28.0 pyo3_testing version numbers will shadow pyo3’s left-most non-zero major/minor version. E.g. v0.28.x matches v0.28.x. This is to simplify things so that you and cargo can always find the right match.

Details of previous compatible versions are in the readme.

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.