Skip to content

Commit b1a6c0d

Browse files
author
Andrew J Westlake
committed
Added suite_name argument to test main
1 parent 25753a5 commit b1a6c0d

File tree

2 files changed

+60
-54
lines changed

2 files changed

+60
-54
lines changed

pytests/test_asyncio.rs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,40 +90,43 @@ fn test_blocking_sleep() {
9090
}
9191

9292
fn main() {
93-
test_main(vec![
94-
Test::new_async(
95-
"test_async_sleep".into(),
96-
Python::with_gil(|py| {
97-
test_async_sleep(py)
98-
.map_err(|e| {
99-
e.print_and_set_sys_last_vars(py);
100-
})
101-
.unwrap()
93+
test_main(
94+
"PyO3 Asyncio Test Suite",
95+
vec![
96+
Test::new_async(
97+
"test_async_sleep".into(),
98+
Python::with_gil(|py| {
99+
test_async_sleep(py)
100+
.map_err(|e| {
101+
e.print_and_set_sys_last_vars(py);
102+
})
103+
.unwrap()
104+
}),
105+
),
106+
Test::new_sync("test_blocking_sleep".into(), || {
107+
test_blocking_sleep();
108+
Ok(())
102109
}),
103-
),
104-
Test::new_sync("test_blocking_sleep".into(), || {
105-
test_blocking_sleep();
106-
Ok(())
107-
}),
108-
Test::new_async(
109-
"test_into_coroutine".into(),
110-
Python::with_gil(|py| {
111-
test_into_coroutine(py)
112-
.map_err(|e| {
113-
e.print_and_set_sys_last_vars(py);
114-
})
115-
.unwrap()
116-
}),
117-
),
118-
Test::new_async(
119-
"test_into_future".into(),
120-
Python::with_gil(|py| {
121-
test_into_future(py)
122-
.map_err(|e| {
123-
e.print_and_set_sys_last_vars(py);
124-
})
125-
.unwrap()
126-
}),
127-
),
128-
])
110+
Test::new_async(
111+
"test_into_coroutine".into(),
112+
Python::with_gil(|py| {
113+
test_into_coroutine(py)
114+
.map_err(|e| {
115+
e.print_and_set_sys_last_vars(py);
116+
})
117+
.unwrap()
118+
}),
119+
),
120+
Test::new_async(
121+
"test_into_future".into(),
122+
Python::with_gil(|py| {
123+
test_into_future(py)
124+
.map_err(|e| {
125+
e.print_and_set_sys_last_vars(py);
126+
})
127+
.unwrap()
128+
}),
129+
),
130+
],
131+
)
129132
}

src/testing.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//!
5050
//! ```no_run
5151
//! fn main() {
52-
//! pyo3_asyncio::testing::test_main(vec![]);
52+
//! pyo3_asyncio::testing::test_main("Example Test Suite", vec![]);
5353
//! }
5454
//! ```
5555
//!
@@ -59,22 +59,25 @@
5959
//! use pyo3_asyncio::testing::Test;
6060
//!
6161
//! fn main() {
62-
//! pyo3_asyncio::testing::test_main(vec![
63-
//! Test::new_async(
64-
//! "test_async_sleep".into(),
65-
//! async move {
66-
//! // async test body
67-
//! Ok(())
68-
//! }
69-
//! ),
70-
//! Test::new_sync(
71-
//! "test_blocking_sleep".into(),
72-
//! || {
73-
//! // blocking test body
74-
//! Ok(())
75-
//! }
76-
//! ),
77-
//! ]);
62+
//! pyo3_asyncio::testing::test_main(
63+
//! "Example Test Suite",
64+
//! vec![
65+
//! Test::new_async(
66+
//! "test_async_sleep".into(),
67+
//! async move {
68+
//! // async test body
69+
//! Ok(())
70+
//! }
71+
//! ),
72+
//! Test::new_sync(
73+
//! "test_blocking_sleep".into(),
74+
//! || {
75+
//! // blocking test body
76+
//! Ok(())
77+
//! }
78+
//! ),
79+
//! ]
80+
//! );
7881
//! }
7982
//! ```
8083
@@ -204,10 +207,10 @@ pub async fn test_harness(tests: Vec<Test>, args: Args) -> PyResult<()> {
204207
/// This is meant to perform the necessary initialization for most test cases. If you want
205208
/// additional control over the initialization (i.e. env_logger initialization), you can use this
206209
/// function as a template.
207-
pub fn test_main(tests: Vec<Test>) {
210+
pub fn test_main(suite_name: &str, tests: Vec<Test>) {
208211
Python::with_gil(|py| {
209212
with_runtime(py, || {
210-
let args = parse_args("Pyo3 Asyncio Test Suite");
213+
let args = parse_args(suite_name);
211214

212215
run_until_complete(py, test_harness(tests, args))?;
213216
Ok(())

0 commit comments

Comments
 (0)