Attribute Macro pyo3_asyncio::async_std::test

#[test]
Expand description

attributes testing Registers an async-std test with the pyo3-asyncio test harness Registers an async-std 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 #[async_std::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::async_std::test]
async fn test_async_sleep() -> PyResult<()> {
    async_std::task::sleep(Duration::from_secs(1)).await;
    Ok(())
}

// blocking test function
#[pyo3_asyncio::async_std::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::async_std::test]
fn test_blocking_sleep_with_event_loop(event_loop: PyObject) -> PyResult<()> {
    thread::sleep(Duration::from_secs(1));
    Ok(())
}