@@ -226,7 +226,16 @@ def test_more_fail():
226
226
assert_outcomes (rr , {"failed" : 1 })
227
227
228
228
229
- def test_inlineCallbacks (testdir , cmd_opts ):
229
+ @pytest .fixture (
230
+ name = "empty_optional_call" ,
231
+ params = ["" , "()" ],
232
+ ids = ["no call" , "empty call" ],
233
+ )
234
+ def empty_optional_call_fixture (request ):
235
+ return request .param
236
+
237
+
238
+ def test_inlineCallbacks (testdir , cmd_opts , empty_optional_call ):
230
239
test_file = """
231
240
from twisted.internet import reactor, defer
232
241
import pytest
@@ -236,19 +245,19 @@ def test_inlineCallbacks(testdir, cmd_opts):
236
245
def foo(request):
237
246
return request.param
238
247
239
- @pytest_twisted.inlineCallbacks
248
+ @pytest_twisted.inlineCallbacks{optional_call}
240
249
def test_succeed(foo):
241
250
yield defer.succeed(foo)
242
251
if foo == "web":
243
252
raise RuntimeError("baz")
244
- """
253
+ """ . format ( optional_call = empty_optional_call )
245
254
testdir .makepyfile (test_file )
246
255
rr = testdir .run (sys .executable , "-m" , "pytest" , "-v" , * cmd_opts )
247
256
assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
248
257
249
258
250
259
@skip_if_no_async_await ()
251
- def test_async_await (testdir , cmd_opts ):
260
+ def test_async_await (testdir , cmd_opts , empty_optional_call ):
252
261
test_file = """
253
262
from twisted.internet import reactor, defer
254
263
import pytest
@@ -258,12 +267,12 @@ def test_async_await(testdir, cmd_opts):
258
267
def foo(request):
259
268
return request.param
260
269
261
- @pytest_twisted.ensureDeferred
270
+ @pytest_twisted.ensureDeferred{optional_call}
262
271
async def test_succeed(foo):
263
272
await defer.succeed(foo)
264
273
if foo == "web":
265
274
raise RuntimeError("baz")
266
- """
275
+ """ . format ( optional_call = empty_optional_call )
267
276
testdir .makepyfile (test_file )
268
277
rr = testdir .run (sys .executable , "-m" , "pytest" , "-v" , * cmd_opts )
269
278
assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
@@ -376,6 +385,25 @@ def test_succeed_blue(foo):
376
385
assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
377
386
378
387
388
+ @skip_if_no_async_await ()
389
+ def test_async_fixture_no_arguments (testdir , cmd_opts , empty_optional_call ):
390
+ test_file = """
391
+ from twisted.internet import reactor, defer
392
+ import pytest
393
+ import pytest_twisted
394
+
395
+ @pytest_twisted.async_fixture{optional_call}
396
+ async def scope(request):
397
+ return request.scope
398
+
399
+ def test_is_function_scope(scope):
400
+ assert scope == "function"
401
+ """ .format (optional_call = empty_optional_call )
402
+ testdir .makepyfile (test_file )
403
+ rr = testdir .run (sys .executable , "-m" , "pytest" , "-v" , * cmd_opts )
404
+ assert_outcomes (rr , {"passed" : 1 })
405
+
406
+
379
407
@skip_if_no_async_generators ()
380
408
def test_async_yield_fixture_concurrent_teardown (testdir , cmd_opts ):
381
409
test_file = """
@@ -453,6 +481,29 @@ def test_succeed(foo):
453
481
assert_outcomes (rr , {"passed" : 4 , "failed" : 1 , "errors" : 2 })
454
482
455
483
484
+ @skip_if_no_async_generators ()
485
+ def test_async_yield_fixture_no_arguments (
486
+ testdir ,
487
+ cmd_opts ,
488
+ empty_optional_call ,
489
+ ):
490
+ test_file = """
491
+ from twisted.internet import reactor, defer
492
+ import pytest
493
+ import pytest_twisted
494
+
495
+ @pytest_twisted.async_yield_fixture{optional_call}
496
+ async def scope(request):
497
+ yield request.scope
498
+
499
+ def test_is_function_scope(scope):
500
+ assert scope == "function"
501
+ """ .format (optional_call = empty_optional_call )
502
+ testdir .makepyfile (test_file )
503
+ rr = testdir .run (sys .executable , "-m" , "pytest" , "-v" , * cmd_opts )
504
+ assert_outcomes (rr , {"passed" : 1 })
505
+
506
+
456
507
@skip_if_no_async_generators ()
457
508
def test_async_yield_fixture_function_scope (testdir , cmd_opts ):
458
509
test_file = """
0 commit comments