Skip to content

Commit dde84b3

Browse files
authored
Merge pull request #147 from axiomiety/tests-exception-groups
[tests] support trio's new exception groups, bump min trio rev to 0.25.0
2 parents ffbd11c + 91c7360 commit dde84b3

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

docs-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sphinx >= 1.7.0
22
sphinx_rtd_theme
33
sphinxcontrib-trio
44
towncrier
5-
trio >= 0.15.0,< 0.25.0
5+
trio >= 0.25.0
66
outcome
77
attrs
88
greenlet

newsfragments/146.misc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated test suite to cope with Trio 0.25.0 and later defaulting ``strict_exception_groups`` to ``True``. Trio 0.25.0 is now required to run the tests, although trio-asyncio itself still supports older versions.

test-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pytest-cov
33
pytest-trio
44
outcome
55
pytest-timeout
6-
trio >= 0.15.0,< 0.25.0
6+
trio >= 0.25.0

tests/interop/test_calls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ async def cancel_trio(seen):
299299
seen.flag |= 8
300300

301301
seen = Seen()
302-
with pytest.raises(asyncio.CancelledError):
302+
with trio.testing.RaisesGroup(asyncio.CancelledError):
303303
await cancel_trio(seen)
304304
assert seen.flag == 1 | 8
305305

tests/test_misc.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async def run_asyncio_loop(nursery, *, task_status=trio.TASK_STATUS_IGNORED):
225225
import signal
226226
import threading
227227

228-
with pytest.raises(KeyboardInterrupt):
228+
with trio.testing.RaisesGroup(KeyboardInterrupt):
229229
async with trio.open_nursery() as nursery:
230230
await nursery.start(run_asyncio_loop, nursery)
231231
# Trigger KeyboardInterrupt that should propagate accross the coroutines
@@ -270,7 +270,7 @@ async def trio_task():
270270
scope.cancel()
271271
assert fut.done()
272272
if throw_another:
273-
with pytest.raises(ValueError, match="hi"):
273+
with trio.testing.RaisesGroup(trio.testing.Matcher(ValueError, match="hi")):
274274
fut.result()
275275
else:
276276
assert fut.cancelled()
@@ -333,12 +333,19 @@ def collect_exceptions(loop, context):
333333
)
334334
expected = [ValueError("hi"), ValueError("lo"), KeyError(), IndexError()]
335335
await raise_in_aio_loop(expected[0])
336-
with pytest.raises(SystemExit):
336+
with trio.testing.RaisesGroup(SystemExit, strict=False):
337337
await raise_in_aio_loop(SystemExit(0))
338-
with pytest.raises(BaseExceptionGroup) as result:
338+
with trio.testing.RaisesGroup(SystemExit, strict=False) as result:
339339
await raise_in_aio_loop(BaseExceptionGroup("", [expected[1], SystemExit()]))
340+
340341
assert len(result.value.exceptions) == 1
341-
assert isinstance(result.value.exceptions[0], SystemExit)
342+
343+
def innermost_exception(item):
344+
if isinstance(item, BaseExceptionGroup):
345+
return innermost_exception(item.exceptions[0])
346+
return item
347+
348+
assert isinstance(innermost_exception(result.value), SystemExit)
342349
await raise_in_aio_loop(ExceptionGroup("", expected[2:]))
343350

344351
assert len(exceptions) == 3

tests/test_trio_asyncio.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ async def test_cancel_loop_with_tasks(autojump_clock, shield, body_raises):
121121
record = []
122122

123123
if body_raises:
124-
catcher = pytest.raises(ValueError, match="hi")
124+
catcher = trio.testing.RaisesGroup(
125+
trio.testing.Matcher(ValueError, match="hi"), strict=False
126+
)
125127
else:
126128
catcher = contextlib.nullcontext()
127129

0 commit comments

Comments
 (0)