Skip to content

Writing tests in Rust for a python extension #2733

Answered by davidhewitt
Adoni5 asked this question in Questions
Discussion options

You must be logged in to vote

Hi, sorry for the slow reply.

You can indeed write tests from Rust, you should make sure to disable the extension-module feature and instead enable the auto-initialize feature while running tests.

For some examples, see our tests we have internally for string conversions:

mod tests {
use crate::Python;
use crate::{FromPyObject, IntoPy, PyObject, ToPyObject};
use std::borrow::Cow;
#[test]
fn test_cow_into_py() {
Python::with_gil(|py| {
let s = "Hello Python";
let py_string: PyObject = Cow::Borrowed(s).into_py(py);
assert_eq!(s, py_string.extract::<&str>(py).unwrap());

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Adoni5
Comment options

Answer selected by Adoni5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants