@@ -179,6 +179,11 @@ def handler(*args, **kwargs):
179
179
)
180
180
181
181
182
+ ######################################################################
183
+ # 2025-02: Generator handlers deprecated in 0.5.0
184
+ ######################################################################
185
+
186
+
182
187
def test_generator_handler (event_loop ):
183
188
"""A generator can be used as a handler."""
184
189
obj = Mock ()
@@ -198,10 +203,15 @@ def handler(*args, **kwargs):
198
203
# Raw handler is the original generator
199
204
assert wrapped ._raw == handler
200
205
201
- # Invoke the handler, and run until it is complete.
202
- assert (
203
- event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 )) == 42
204
- )
206
+ # Invoke the handler, and run until it is complete. Raises a deprecation warning.
207
+ with pytest .warns (
208
+ DeprecationWarning ,
209
+ match = r"Use of generators for async handlers has been deprecated;" ,
210
+ ):
211
+ assert (
212
+ event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 ))
213
+ == 42
214
+ )
205
215
206
216
# Handler arguments are as expected.
207
217
assert handler_call == {
@@ -228,11 +238,16 @@ def handler(*args, **kwargs):
228
238
# Raw handler is the original generator
229
239
assert wrapped ._raw == handler
230
240
231
- # Invoke the handler; return value is None due to exception
232
- assert (
233
- event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 ))
234
- is None
235
- )
241
+ # Invoke the handler; raises a deprecation warning, return value is None due to
242
+ # exception.
243
+ with pytest .warns (
244
+ DeprecationWarning ,
245
+ match = r"Use of generators for async handlers has been deprecated;" ,
246
+ ):
247
+ assert (
248
+ event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 ))
249
+ is None
250
+ )
236
251
237
252
# Handler arguments are as expected.
238
253
assert handler_call == {
@@ -267,10 +282,15 @@ def handler(*args, **kwargs):
267
282
# Raw handler is the original generator
268
283
assert wrapped ._raw == handler
269
284
270
- # Invoke the handler
271
- assert (
272
- event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 )) == 42
273
- )
285
+ # Invoke the handler; raises a deprecation warning
286
+ with pytest .warns (
287
+ DeprecationWarning ,
288
+ match = r"Use of generators for async handlers has been deprecated;" ,
289
+ ):
290
+ assert (
291
+ event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 ))
292
+ == 42
293
+ )
274
294
275
295
# Handler arguments are as expected.
276
296
assert handler_call == {
@@ -304,10 +324,15 @@ def handler(*args, **kwargs):
304
324
# Raw handler is the original generator
305
325
assert wrapped ._raw == handler
306
326
307
- # Invoke the handler; error in cleanup is swallowed
308
- assert (
309
- event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 )) == 42
310
- )
327
+ # Invoke the handler; raises a deprecation warning, error in cleanup is swallowed
328
+ with pytest .warns (
329
+ DeprecationWarning ,
330
+ match = r"Use of generators for async handlers has been deprecated;" ,
331
+ ):
332
+ assert (
333
+ event_loop .run_until_complete (wrapped ("arg1" , "arg2" , kwarg1 = 3 , kwarg2 = 4 ))
334
+ == 42
335
+ )
311
336
312
337
# Handler arguments are as expected.
313
338
assert handler_call == {
@@ -327,6 +352,9 @@ def handler(*args, **kwargs):
327
352
)
328
353
329
354
355
+ ######################################################################
356
+
357
+
330
358
def test_coroutine_handler (event_loop ):
331
359
"""A coroutine can be used as a handler."""
332
360
obj = Mock ()
0 commit comments