diff --git a/docs-requirements.txt b/docs-requirements.txt index f546b2e..169a38a 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -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 diff --git a/newsfragments/146.bugfix.rst b/newsfragments/146.bugfix.rst new file mode 100644 index 0000000..d74f938 --- /dev/null +++ b/newsfragments/146.bugfix.rst @@ -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`. diff --git a/test-requirements.txt b/test-requirements.txt index 304a4fc..bb660a4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,4 +3,4 @@ pytest-cov pytest-trio outcome pytest-timeout -trio >= 0.15.0,< 0.25.0 +trio >= 0.25.0 diff --git a/tests/interop/test_calls.py b/tests/interop/test_calls.py index f77ba40..59c0197 100644 --- a/tests/interop/test_calls.py +++ b/tests/interop/test_calls.py @@ -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 diff --git a/tests/test_misc.py b/tests/test_misc.py index 2343a41..de62beb 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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 @@ -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() @@ -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 diff --git a/tests/test_trio_asyncio.py b/tests/test_trio_asyncio.py index 5afb17a..fb36dd5 100644 --- a/tests/test_trio_asyncio.py +++ b/tests/test_trio_asyncio.py @@ -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()