30
30
//! [`#[pyo3_asyncio::async_std::test]`](crate::async_std::test) and run them automatically.
31
31
//!
32
32
//! `pytests/test_example.rs` for the `tokio` runtime:
33
- //! ```
34
- //! # #[cfg(feature = "tokio-runtime attributes")]
33
+ //! ```ignore
34
+ //! # #[cfg(all( feature = "tokio-runtime", feature = " attributes") )]
35
35
//! pyo3_asyncio::testing::test_main!(#[pyo3_asyncio::tokio::main], "Example Test Suite");
36
36
//! ```
37
37
//!
38
38
//! `pytests/test_example.rs` for the `async-std` runtime:
39
- //! ```
40
- //! # #[cfg(feature = "async-std-runtime attributes")]
39
+ //! ```ignore
40
+ //! # #[cfg(all( feature = "async-std-runtime", feature = " attributes") )]
41
41
//! pyo3_asyncio::testing::test_main!(#[pyo3_asyncio::async_std::main], "Example Test Suite");
42
42
//! ```
43
43
//!
73
73
//!
74
74
//! For `async-std` use the [`pyo3_asyncio::async_std::test`](crate::async_std::test) attribute:
75
75
//! ```
76
- //! # #[cfg(feature = "async-std-runtime attributes")]
76
+ //! # #[cfg(all( feature = "async-std-runtime", feature = " attributes") )]
77
77
//! # mod tests {
78
78
//! use std::{time::Duration, thread};
79
79
//!
96
96
//! #
97
97
//! # // Doctests don't detect main fn when using the test_main!() macro, so we expand it into the
98
98
//! # // components of that macro instead.
99
- //! # #[cfg(feature = "async-std-runtime attributes")]
99
+ //! #
100
+ //! # #[cfg(all(feature = "async-std-runtime", feature = "attributes"))]
101
+ //! # use pyo3::prelude::*;
102
+ //! #
103
+ //! # #[cfg(all(feature = "async-std-runtime", feature = "attributes"))]
100
104
//! # pyo3_asyncio::testing::test_structs!();
101
105
//! #
102
- //! # #[cfg(feature = "async-std-runtime attributes")]
106
+ //! # #[cfg(all( feature = "async-std-runtime", feature = " attributes") )]
103
107
//! # #[pyo3_asyncio::async_std::main]
104
108
//! # async fn main() -> pyo3::PyResult<()> {
105
109
//! # pyo3_asyncio::testing::test_main_body!("Example Test Suite");
106
110
//! #
107
111
//! # Ok(())
108
112
//! # }
109
- //! # #[cfg(not(feature = "async-std-runtime attributes"))]
113
+ //! # #[cfg(not(all( feature = "async-std-runtime", feature = " attributes") ))]
110
114
//! # fn main() {}
111
115
//! ```
112
116
//!
113
117
//! For `tokio` use the [`pyo3_asyncio::tokio::test`](crate::tokio::test) attribute:
114
118
//! ```
115
- //! # #[cfg(feature = "tokio-runtime attributes")]
119
+ //! # #[cfg(all( feature = "tokio-runtime", feature = " attributes") )]
116
120
//! # mod tests {
117
121
//! use std::{time::Duration, thread};
118
122
//!
135
139
//! #
136
140
//! # // Doctests don't detect main fn when using the test_main!() macro, so we expand it into the
137
141
//! # // components of that macro instead.
138
- //! # #[cfg(feature = "tokio-runtime attributes")]
142
+ //! # #[cfg(all(feature = "tokio-runtime", feature = "attributes"))]
143
+ //! # use pyo3::prelude::*;
144
+ //! #
145
+ //! # #[cfg(all(feature = "tokio-runtime", feature = "attributes"))]
139
146
//! # pyo3_asyncio::testing::test_structs!();
140
147
//! #
141
- //! # #[cfg(feature = "tokio-runtime attributes")]
148
+ //! # #[cfg(all( feature = "tokio-runtime", feature = " attributes") )]
142
149
//! # #[pyo3_asyncio::tokio::main]
143
150
//! # async fn main() -> PyResult<()> {
144
151
//! # pyo3_asyncio::testing::test_main_body!("Example Test Suite");
145
152
//! #
146
153
//! # Ok(())
147
154
//! # }
148
- //! # #[cfg(not(feature = "tokio-runtime attributes"))]
155
+ //! # #[cfg(not(all( feature = "tokio-runtime", feature = " attributes") ))]
149
156
//! # fn main() {}
150
157
//! ```
151
158
//!
172
179
//!
173
180
//! `my-crate/src/lib.rs`
174
181
//! ```
175
- //! # #[cfg(any(feature = "async-std-runtime attributes", feature = "tokio-runtime attributes"))]
182
+ //! # #[cfg(all(
183
+ //! # any(feature = "async-std-runtime", feature = "tokio-runtime"),
184
+ //! # feature = "attributes"
185
+ //! # ))]
176
186
//! pyo3_asyncio::testing::test_structs!();
177
187
//!
178
- //! # #[cfg(any(feature = "async-std-runtime attributes", feature = "tokio-runtime attributes"))]
188
+ //! # #[cfg(all(
189
+ //! # any(feature = "async-std-runtime", feature = "tokio-runtime"),
190
+ //! # feature = "attributes"
191
+ //! # ))]
179
192
//! mod tests {
180
193
//! use pyo3::prelude::*;
181
- //!
182
- //! use crate as pyo3_asyncio;
183
194
//!
184
- //! # #[cfg(feature = "async-std-runtime attributes ")]
195
+ //! # #[cfg(feature = "async-std-runtime")]
185
196
//! #[pyo3_asyncio::async_std::test]
186
197
//! async fn test_async_std_async_test_compiles() -> PyResult<()> {
187
198
//! Ok(())
188
199
//! }
189
- //! # #[cfg(feature = "async-std-runtime attributes ")]
200
+ //! # #[cfg(feature = "async-std-runtime")]
190
201
//! #[pyo3_asyncio::async_std::test]
191
202
//! fn test_async_std_sync_test_compiles() -> PyResult<()> {
192
203
//! Ok(())
193
204
//! }
194
205
//!
195
- //! # #[cfg(feature = "tokio-runtime attributes ")]
206
+ //! # #[cfg(feature = "tokio-runtime")]
196
207
//! #[pyo3_asyncio::tokio::test]
197
208
//! async fn test_tokio_async_test_compiles() -> PyResult<()> {
198
209
//! Ok(())
199
210
//! }
200
- //! # #[cfg(feature = "tokio-runtime attributes ")]
211
+ //! # #[cfg(feature = "tokio-runtime")]
201
212
//! #[pyo3_asyncio::tokio::test]
202
213
//! fn test_tokio_sync_test_compiles() -> PyResult<()> {
203
214
//! Ok(())
204
215
//! }
205
216
//! }
217
+ //!
218
+ //! # fn main() {}
206
219
//! ```
207
220
//!
208
221
//! #### Expanding `test_main!()` for Doc Tests
223
236
//!
224
237
//! The following `test_main!()` macro:
225
238
//!
226
- //! ```
227
- //! # #[cfg(feature = "async-std-runtime attributes")]
239
+ //! ```ignore
228
240
//! pyo3_asyncio::testing::test_main!(#[pyo3_asyncio::async_std::main], "Example Test Suite");
229
241
//! ```
230
242
//!
231
243
//! Is equivalent to this expansion:
232
244
//!
233
245
//! ```
234
- //! # #[cfg(feature = "async-std-runtime attributes")]
246
+ //! # #[cfg(all( feature = "async-std-runtime", feature = " attributes") )]
235
247
//! use pyo3::prelude::*;
236
248
//!
237
- //! # #[cfg(feature = "async-std-runtime attributes")]
249
+ //! # #[cfg(all( feature = "async-std-runtime", feature = " attributes") )]
238
250
//! pyo3_asyncio::testing::test_structs!();
239
251
//!
240
- //! # #[cfg(feature = "async-std-runtime attributes")]
252
+ //! # #[cfg(all( feature = "async-std-runtime", feature = " attributes") )]
241
253
//! #[pyo3_asyncio::async_std::main]
242
254
//! async fn main() -> PyResult<()> {
243
255
//! pyo3_asyncio::testing::test_main_body!("Example Test Suite");
244
256
//! Ok(())
245
257
//! }
246
- //! # #[cfg(not(feature = "async-std-runtime attributes"))]
258
+ //! # #[cfg(not(all( feature = "async-std-runtime", feature = " attributes") ))]
247
259
//! # fn main() {}
248
260
//! ```
249
261
@@ -254,14 +266,17 @@ use futures::stream::{self, StreamExt};
254
266
use pyo3:: prelude:: * ;
255
267
256
268
/// <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>attributes</code></span>
269
+ /// Provides the boilerplate for the `pyo3-asyncio` test harness in one line
257
270
#[ cfg( feature = "attributes" ) ]
258
271
pub use pyo3_asyncio_macros:: test_main;
259
272
260
273
/// <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>attributes</code></span>
274
+ /// Provides the `Test` structure and the `inventory` boilerplate for the `pyo3-asyncio` test harness
261
275
#[ cfg( feature = "attributes" ) ]
262
276
pub use pyo3_asyncio_macros:: test_structs;
263
277
264
278
/// <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>attributes</code></span>
279
+ /// Expands the `pyo3-asyncio` test harness call within the `main` fn
265
280
#[ cfg( feature = "attributes" ) ]
266
281
pub use pyo3_asyncio_macros:: test_main_body;
267
282
0 commit comments