@@ -494,6 +494,88 @@ def test_second(foo):
494494 assert_outcomes (rr , {"passed" : 2 })
495495
496496
497+ @skip_if_no_async_await ()
498+ def test_async_fixture_in_fixture (testdir , cmd_opts ):
499+ test_file = """
500+ import itertools
501+ from twisted.internet import reactor, defer
502+ import pytest
503+ import pytest_twisted
504+
505+ @pytest_twisted.async_fixture(name='increment')
506+ async def fixture_increment():
507+ counts = itertools.count()
508+ async def increment():
509+ return next(counts)
510+
511+ return increment
512+
513+ @pytest_twisted.async_fixture(name='doubleincrement')
514+ async def fixture_doubleincrement(increment):
515+ async def doubleincrement():
516+ n = await increment()
517+ return n * 2
518+
519+ return doubleincrement
520+
521+ @pytest_twisted.ensureDeferred
522+ async def test_increment(increment):
523+ first = await increment()
524+ second = await increment()
525+ assert (first, second) == (0, 1)
526+
527+ @pytest_twisted.ensureDeferred
528+ async def test_doubleincrement(doubleincrement):
529+ first = await doubleincrement()
530+ second = await doubleincrement()
531+ assert (first, second) == (0, 2)
532+ """
533+ testdir .makepyfile (test_file )
534+ rr = testdir .run (sys .executable , "-m" , "pytest" , "-v" , * cmd_opts )
535+ assert_outcomes (rr , {"passed" : 2 })
536+
537+
538+ @skip_if_no_async_generators ()
539+ def test_async_yield_fixture_in_fixture (testdir , cmd_opts ):
540+ test_file = """
541+ import itertools
542+ from twisted.internet import reactor, defer
543+ import pytest
544+ import pytest_twisted
545+
546+ @pytest_twisted.async_yield_fixture(name='increment')
547+ async def fixture_increment():
548+ counts = itertools.count()
549+ async def increment():
550+ return next(counts)
551+
552+ yield increment
553+
554+ @pytest_twisted.async_yield_fixture(name='doubleincrement')
555+ async def fixture_doubleincrement(increment):
556+ async def doubleincrement():
557+ n = await increment()
558+ return n * 2
559+
560+ yield doubleincrement
561+
562+ @pytest_twisted.ensureDeferred
563+ async def test_increment(increment):
564+ first = await increment()
565+ second = await increment()
566+ assert (first, second) == (0, 1)
567+
568+ @pytest_twisted.ensureDeferred
569+ async def test_doubleincrement(doubleincrement):
570+ first = await doubleincrement()
571+ second = await doubleincrement()
572+ assert (first, second) == (0, 2)
573+ """
574+ testdir .makepyfile (test_file )
575+ rr = testdir .run (sys .executable , "-m" , "pytest" , "-v" , * cmd_opts )
576+ assert_outcomes (rr , {"passed" : 2 })
577+
578+
497579def test_blockon_in_hook (testdir , cmd_opts , request ):
498580 skip_if_reactor_not (request , "default" )
499581 conftest_file = """
0 commit comments