Skip to content

Commit

Permalink
[tests] support trio's new exception groups, bump min trio rev to 0.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Moschetta committed Apr 19, 2024
1 parent ffbd11c commit b811211
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sphinx >= 1.7.0
sphinx_rtd_theme
sphinxcontrib-trio
towncrier
trio >= 0.15.0,< 0.25.0
trio >= 0.25.0
outcome
attrs
greenlet
1 change: 1 addition & 0 deletions newsfragments/146.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In 0.24.0 ``trio`` introduced `~trio.testing.RaisesGroup` in preparation for changing the default of ``strict_exception_groups`` to ``True``. 0.25.0 made this the new default which broke a number of tests that relied on ``pytest.raises`` - this uplifts the tests to using `~trio.testing.RaisesGroup`.
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pytest-cov
pytest-trio
outcome
pytest-timeout
trio >= 0.15.0,< 0.25.0
trio >= 0.25.0
2 changes: 1 addition & 1 deletion tests/interop/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ async def cancel_trio(seen):
seen.flag |= 8

seen = Seen()
with pytest.raises(asyncio.CancelledError):
with trio.testing.RaisesGroup(asyncio.CancelledError):
await cancel_trio(seen)
assert seen.flag == 1 | 8

Expand Down
15 changes: 10 additions & 5 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def run_asyncio_loop(nursery, *, task_status=trio.TASK_STATUS_IGNORED):
import signal
import threading

with pytest.raises(KeyboardInterrupt):
with trio.testing.RaisesGroup(KeyboardInterrupt):
async with trio.open_nursery() as nursery:
await nursery.start(run_asyncio_loop, nursery)
# Trigger KeyboardInterrupt that should propagate accross the coroutines
Expand Down Expand Up @@ -270,7 +270,7 @@ async def trio_task():
scope.cancel()
assert fut.done()
if throw_another:
with pytest.raises(ValueError, match="hi"):
with trio.testing.RaisesGroup(trio.testing.Matcher(ValueError, match="hi")):
fut.result()
else:
assert fut.cancelled()
Expand Down Expand Up @@ -333,12 +333,17 @@ def collect_exceptions(loop, context):
)
expected = [ValueError("hi"), ValueError("lo"), KeyError(), IndexError()]
await raise_in_aio_loop(expected[0])
with pytest.raises(SystemExit):
with trio.testing.RaisesGroup(SystemExit, strict=False):
await raise_in_aio_loop(SystemExit(0))
with pytest.raises(BaseExceptionGroup) as result:
with trio.testing.RaisesGroup(SystemExit, strict=False) as result:
await raise_in_aio_loop(BaseExceptionGroup("", [expected[1], SystemExit()]))

assert len(result.value.exceptions) == 1
assert isinstance(result.value.exceptions[0], SystemExit)
def innermost_exception(item):
if isinstance(item, BaseExceptionGroup):
return innermost_exception(item.exceptions[0])
return item
assert isinstance(innermost_exception(result.value), SystemExit)
await raise_in_aio_loop(ExceptionGroup("", expected[2:]))

assert len(exceptions) == 3
Expand Down
2 changes: 1 addition & 1 deletion tests/test_trio_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def test_cancel_loop_with_tasks(autojump_clock, shield, body_raises):
record = []

if body_raises:
catcher = pytest.raises(ValueError, match="hi")
catcher = trio.testing.RaisesGroup(trio.testing.Matcher(ValueError, match="hi"), strict=False)
else:
catcher = contextlib.nullcontext()

Expand Down

0 comments on commit b811211

Please sign in to comment.