Skip to content

Commit 47510b6

Browse files
authored
Merge pull request #115 from altendky/fixup_async_yield_fixture_teardown_exception
Separate and correct test for async yield fixture teardown exception …
2 parents 09a32d6 + 55bfbd8 commit 47510b6

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

pytest_twisted.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,6 @@ def tear_it_down(deferred):
323323
yield deferred
324324
except StopAsyncIteration:
325325
return
326-
except Exception: # as e:
327-
pass
328-
# e = e
329-
else:
330-
pass
331-
# e = None
332326

333327
# TODO: six.raise_from()
334328
raise AsyncGeneratorFixtureDidNotStopError.from_generator(

testing/test_basic.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def test_async_yield_fixture(testdir, cmd_opts):
458458
459459
@pytest_twisted.async_yield_fixture(
460460
scope="function",
461-
params=["fs", "imap", "web", "gopher", "archie"],
461+
params=["fs", "imap", "web", "archie"],
462462
)
463463
async def foo(request):
464464
d1, d2 = defer.Deferred(), defer.Deferred()
@@ -471,9 +471,6 @@ async def foo(request):
471471
# https://github.com/twisted/twisted/blob/c0f1394c7bfb04d97c725a353a1f678fa6a1c602/src/twisted/internet/defer.py#L459
472472
yield d2,
473473
474-
if request.param == "gopher":
475-
raise RuntimeError("gaz")
476-
477474
if request.param == "archie":
478475
yield 42
479476
@@ -486,7 +483,34 @@ def test_succeed(foo):
486483
testdir.makepyfile(test_file)
487484
rr = testdir.run(*cmd_opts, timeout=timeout)
488485
# TODO: this is getting super imprecise...
489-
assert_outcomes(rr, {"passed": 4, "failed": 1, "errors": 2})
486+
assert_outcomes(rr, {"passed": 3, "failed": 1, "errors": 1})
487+
488+
489+
@skip_if_no_async_generators()
490+
def test_async_yield_fixture_teardown_exception(testdir, cmd_opts):
491+
test_file = """
492+
from twisted.internet import reactor, defer
493+
import pytest
494+
import pytest_twisted
495+
496+
class UniqueLocalException(Exception):
497+
pass
498+
499+
@pytest_twisted.async_yield_fixture()
500+
async def foo(request):
501+
yield 13
502+
503+
raise UniqueLocalException("some message")
504+
505+
@pytest_twisted.ensureDeferred
506+
async def test_succeed(foo):
507+
assert foo == 13
508+
"""
509+
510+
testdir.makepyfile(test_file)
511+
rr = testdir.run(*cmd_opts, timeout=timeout)
512+
rr.stdout.fnmatch_lines(lines2=["E*.UniqueLocalException: some message*"])
513+
assert_outcomes(rr, {"passed": 1, "errors": 1})
490514

491515

492516
@skip_if_no_async_generators()

0 commit comments

Comments
 (0)