pyo3/tests/test_append_to_inittab.rs

33 lines
662 B
Rust
Raw Normal View History

#![cfg(all(feature = "macros", not(PyPy)))]
use pyo3::prelude::*;
#[pyfunction]
fn foo() -> usize {
123
}
#[pymodule]
fn module_with_functions(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(foo, m)?).unwrap();
Ok(())
}
#[cfg(not(PyPy))]
#[test]
fn test_module_append_to_inittab() {
use pyo3::append_to_inittab;
append_to_inittab!(module_with_functions);
Python::with_gil(|py| {
2024-02-05 18:44:00 +00:00
py.run_bound(
r#"
import module_with_functions
assert module_with_functions.foo() == 123
"#,
None,
None,
)
2023-07-21 13:30:02 +00:00
.map_err(|e| e.display(py))
.unwrap();
})
}