Skip to content

Commit 644e279

Browse files
author
Andrew J Westlake
committed
Satisfied some warnings
1 parent ceaaea5 commit 644e279

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

pytests/test_asyncio.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,19 @@ fn test_async_sleep<'p>(
1111
let asyncio = PyObject::from(py.import("asyncio")?);
1212

1313
Ok(async move {
14-
println!("async sleep for 1s");
1514
tokio::time::sleep(Duration::from_secs(1)).await;
1615

17-
println!("asyncio sleep for 1s");
1816
Python::with_gil(|py| {
1917
pyo3_asyncio::into_future(py, asyncio.as_ref(py).call_method1("sleep", (1.0,))?)
2018
})?
2119
.await?;
2220

23-
println!("success!");
24-
2521
Ok(())
2622
})
2723
}
2824

2925
fn test_blocking_sleep() {
30-
println!("blocking sleep for 1s");
3126
thread::sleep(Duration::from_secs(1));
32-
println!("success");
3327
}
3428

3529
fn main() {

src/testing.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use pyo3::prelude::*;
66

77
use crate::{dump_err, run_until_complete, with_runtime};
88

9+
/// Args that should be provided to the test program
10+
///
11+
/// These args are meant to mirror the default test harness's args.
12+
/// > Currently only `--filter` is supported.
913
pub struct Args {
1014
filter: Option<String>,
1115
}
@@ -16,6 +20,10 @@ impl Default for Args {
1620
}
1721
}
1822

23+
/// Parse the test args from the command line
24+
///
25+
/// This should be called at the start of your test harness to give the CLI some
26+
/// control over how our tests are run.
1927
pub fn parse_args(suite_name: &str) -> Args {
2028
let matches = App::new(suite_name)
2129
.arg(
@@ -29,12 +37,14 @@ pub fn parse_args(suite_name: &str) -> Args {
2937
}
3038
}
3139

40+
/// Wrapper around a test function or future to be passed to the test harness
3241
pub struct Test {
33-
pub name: String,
34-
pub task: Pin<Box<dyn Future<Output = PyResult<()>> + Send>>,
42+
name: String,
43+
task: Pin<Box<dyn Future<Output = PyResult<()>> + Send>>,
3544
}
3645

3746
impl Test {
47+
/// Construct a test from a future
3848
pub fn new_async(
3949
name: String,
4050
fut: impl Future<Output = PyResult<()>> + Send + 'static,
@@ -45,6 +55,7 @@ impl Test {
4555
}
4656
}
4757

58+
/// Construct a test from a blocking function (like the traditional `#[test]` attribute)
4859
pub fn new_sync<F>(name: String, func: F) -> Self
4960
where
5061
F: FnOnce() -> PyResult<()> + Send + 'static,
@@ -56,6 +67,7 @@ impl Test {
5667
}
5768
}
5869

70+
/// Run a sequence of tests while applying any necessary filtering from the `Args`
5971
pub async fn test_harness(tests: impl Stream<Item = Test>, args: Args) -> PyResult<()> {
6072
tests
6173
.for_each_concurrent(Some(4), |test| {
@@ -79,6 +91,11 @@ pub async fn test_harness(tests: impl Stream<Item = Test>, args: Args) -> PyResu
7991
Ok(())
8092
}
8193

94+
/// Default main function for the test harness.
95+
///
96+
/// This is meant to perform the necessary initialization for most test cases. If you want
97+
/// additional control over the initialization (i.e. env_logger initialization), you can use this
98+
/// function as a template.
8299
pub fn test_main(tests: impl Stream<Item = Test> + Send + 'static) {
83100
Python::with_gil(|py| {
84101
with_runtime(py, || {

0 commit comments

Comments
 (0)