Replies: 2 comments 3 replies
-
|
fwiw, I tested this with Without So for tests I’d either enable use pyo3::prelude::*;
use std::sync::OnceLock;
fn with_python<F, R>(f: F) -> R
where
F: for<'py> FnOnce(Python<'py>) -> R,
{
static INIT: OnceLock<()> = OnceLock::new();
INIT.get_or_init(Python::initialize);
Python::attach(f)
}Then call The “shared between tests” bit is process-scoped: unit tests in the same Rust test binary share the initialized interpreter, while separate integration test binaries are separate processes, so each binary should initialize before touching Python too. I don’t see a test-specific docs page, mostly the |
Beta Was this translation helpful? Give feedback.
-
|
Another small obstacle I'm encountering is, how do I let Cargo/Pyo3 know what interpreter to use so that my Python module is detected and can be imported while running my Rust test suite. I figured I could try |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
My Rust tests fail with:
Is there documentation on how to write Rust tests that indirectly call
Python::attach()? Should I initialize Python in each test that directly or indirectly uses it? Will the interpreter be shared between each test, or will each test use a different interpreter?Beta Was this translation helpful? Give feedback.
All reactions