Skip to content

Commit 06e855c

Browse files
committed
fewer unused imports, more async def
1 parent f29b136 commit 06e855c

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

testing/test_basic.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ def test_succeed(this, that):
453453
def test_async_yield_fixture_can_await(testdir, cmd_opts):
454454
test_file = """
455455
from twisted.internet import reactor, defer
456-
import pytest
457456
import pytest_twisted
458457
459458
@pytest_twisted.async_yield_fixture()
@@ -468,9 +467,9 @@ async def foo():
468467
# https://github.com/twisted/twisted/blob/c0f1394c7bfb04d97c725a353a1f678fa6a1c602/src/twisted/internet/defer.py#L459
469468
yield d2,
470469
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]
474473
assert x == 2
475474
"""
476475
testdir.makepyfile(test_file)
@@ -481,16 +480,14 @@ def test_succeed(foo):
481480
@skip_if_no_async_generators()
482481
def test_async_yield_fixture_failed_test(testdir, cmd_opts):
483482
test_file = """
484-
from twisted.internet import reactor, defer
485-
import pytest
486483
import pytest_twisted
487484
488485
@pytest_twisted.async_yield_fixture()
489486
async def foo():
490487
yield 92
491488
492-
@pytest_twisted.inlineCallbacks
493-
def test_succeed(foo):
489+
@pytest_twisted.ensureDeferred
490+
async def test(foo):
494491
assert False
495492
"""
496493
testdir.makepyfile(test_file)
@@ -502,8 +499,6 @@ def test_succeed(foo):
502499
@skip_if_no_async_generators()
503500
def test_async_yield_fixture_test_exception(testdir, cmd_opts):
504501
test_file = """
505-
from twisted.internet import reactor, defer
506-
import pytest
507502
import pytest_twisted
508503
509504
class UniqueLocalException(Exception):
@@ -513,8 +508,8 @@ class UniqueLocalException(Exception):
513508
async def foo():
514509
yield 92
515510
516-
@pytest_twisted.inlineCallbacks
517-
def test_succeed(foo):
511+
@pytest_twisted.ensureDeferred
512+
async def test(foo):
518513
raise UniqueLocalException("some message")
519514
"""
520515
testdir.makepyfile(test_file)
@@ -526,22 +521,20 @@ def test_succeed(foo):
526521
@skip_if_no_async_generators()
527522
def test_async_yield_fixture_yields_twice(testdir, cmd_opts):
528523
test_file = """
529-
from twisted.internet import reactor, defer
530-
import pytest
531524
import pytest_twisted
532525
533526
@pytest_twisted.async_yield_fixture()
534527
async def foo():
535528
yield 92
536529
yield 36
537530
538-
@pytest_twisted.inlineCallbacks
539-
def test_succeed(foo):
531+
@pytest_twisted.ensureDeferred
532+
async def test(foo):
540533
assert foo == 92
541534
"""
542535
testdir.makepyfile(test_file)
543536
rr = testdir.run(*cmd_opts, timeout=timeout)
544-
assert_outcomes(rr, {"errors": 1, "failed": 1})
537+
assert_outcomes(rr, {"passed": 1, "errors": 1})
545538

546539

547540
@skip_if_no_async_generators()

0 commit comments

Comments
 (0)