Attribute Macro pyo3_asyncio::tokio::test
#[test]
Expand description
attributes
testing
Registers a tokio
test with the pyo3-asyncio
test harness
Registers a tokio
test with the pyo3-asyncio
test harness.
This attribute is meant to mirror the #[test]
attribute and allow you to mark a function for
testing within an integration test. Like the #[tokio::test]
attribute, it will accept async
test functions, but it will also accept blocking functions as well.
Examples
ⓘ
use std::{time::Duration, thread};
use pyo3::prelude::*;
// async test function
#[pyo3_asyncio::tokio::test]
async fn test_async_sleep() -> PyResult<()> {
tokio::time::sleep(Duration::from_secs(1)).await;
Ok(())
}
// blocking test function
#[pyo3_asyncio::tokio::test]
fn test_blocking_sleep() -> PyResult<()> {
thread::sleep(Duration::from_secs(1));
Ok(())
}
// blocking test functions can optionally accept an event_loop parameter
#[pyo3_asyncio::tokio::test]
fn test_blocking_sleep_with_event_loop(event_loop: PyObject) -> PyResult<()> {
thread::sleep(Duration::from_secs(1));
Ok(())
}