@@ -453,7 +453,6 @@ def test_succeed(this, that):
453
453
def test_async_yield_fixture_can_await (testdir , cmd_opts ):
454
454
test_file = """
455
455
from twisted.internet import reactor, defer
456
- import pytest
457
456
import pytest_twisted
458
457
459
458
@pytest_twisted.async_yield_fixture()
@@ -468,9 +467,9 @@ async def foo():
468
467
# https://github.com/twisted/twisted/blob/c0f1394c7bfb04d97c725a353a1f678fa6a1c602/src/twisted/internet/defer.py#L459
469
468
yield d2,
470
469
471
- @pytest_twisted.inlineCallbacks
472
- def test_succeed (foo):
473
- x = yield foo[0]
470
+ @pytest_twisted.ensureDeferred
471
+ async def test (foo):
472
+ x = await foo[0]
474
473
assert x == 2
475
474
"""
476
475
testdir .makepyfile (test_file )
@@ -481,16 +480,14 @@ def test_succeed(foo):
481
480
@skip_if_no_async_generators ()
482
481
def test_async_yield_fixture_failed_test (testdir , cmd_opts ):
483
482
test_file = """
484
- from twisted.internet import reactor, defer
485
- import pytest
486
483
import pytest_twisted
487
484
488
485
@pytest_twisted.async_yield_fixture()
489
486
async def foo():
490
487
yield 92
491
488
492
- @pytest_twisted.inlineCallbacks
493
- def test_succeed (foo):
489
+ @pytest_twisted.ensureDeferred
490
+ async def test (foo):
494
491
assert False
495
492
"""
496
493
testdir .makepyfile (test_file )
@@ -502,8 +499,6 @@ def test_succeed(foo):
502
499
@skip_if_no_async_generators ()
503
500
def test_async_yield_fixture_test_exception (testdir , cmd_opts ):
504
501
test_file = """
505
- from twisted.internet import reactor, defer
506
- import pytest
507
502
import pytest_twisted
508
503
509
504
class UniqueLocalException(Exception):
@@ -513,8 +508,8 @@ class UniqueLocalException(Exception):
513
508
async def foo():
514
509
yield 92
515
510
516
- @pytest_twisted.inlineCallbacks
517
- def test_succeed (foo):
511
+ @pytest_twisted.ensureDeferred
512
+ async def test (foo):
518
513
raise UniqueLocalException("some message")
519
514
"""
520
515
testdir .makepyfile (test_file )
@@ -526,22 +521,20 @@ def test_succeed(foo):
526
521
@skip_if_no_async_generators ()
527
522
def test_async_yield_fixture_yields_twice (testdir , cmd_opts ):
528
523
test_file = """
529
- from twisted.internet import reactor, defer
530
- import pytest
531
524
import pytest_twisted
532
525
533
526
@pytest_twisted.async_yield_fixture()
534
527
async def foo():
535
528
yield 92
536
529
yield 36
537
530
538
- @pytest_twisted.inlineCallbacks
539
- def test_succeed (foo):
531
+ @pytest_twisted.ensureDeferred
532
+ async def test (foo):
540
533
assert foo == 92
541
534
"""
542
535
testdir .makepyfile (test_file )
543
536
rr = testdir .run (* cmd_opts , timeout = timeout )
544
- assert_outcomes (rr , {"errors " : 1 , "failed " : 1 })
537
+ assert_outcomes (rr , {"passed " : 1 , "errors " : 1 })
545
538
546
539
547
540
@skip_if_no_async_generators ()
0 commit comments