From 805686abfd9963be26d59d9da9b11faddd583d11 Mon Sep 17 00:00:00 2001 From: pgjones Date: Sun, 19 May 2024 15:03:24 +0100 Subject: [PATCH] Fix test failures Catch and extract from ExceptionGroups --- tests/test_app.py | 14 +++++++++----- tests/test_basic.py | 10 ++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/test_app.py b/tests/test_app.py index b6bffb5..1585107 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -51,8 +51,10 @@ async def handler(_: Exception) -> ResponseReturnValue: try: async with test_client.websocket("/ws/") as test_websocket: await test_websocket.receive() - except WebsocketResponseError as error: - assert error.response.status_code == 201 + except BaseExceptionGroup as error: + for exception in error.exceptions: + if isinstance(exception, WebsocketResponseError): + assert exception.response.status_code == 201 @pytest.mark.trio @@ -68,8 +70,10 @@ async def test_websocket_exception_group_unhandled(error_app: QuartTrio) -> None try: async with test_client.websocket("/ws/") as test_websocket: await test_websocket.receive() - except WebsocketResponseError as error: - assert error.response.status_code == 500 + except BaseExceptionGroup as error: + for exception in error.exceptions: + if isinstance(exception, WebsocketResponseError): + assert exception.response.status_code == 500 @pytest.mark.trio diff --git a/tests/test_basic.py b/tests/test_basic.py index 5cc4c4a..a483678 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import pytest @@ -6,6 +7,9 @@ from quart_trio import QuartTrio +if sys.version_info < (3, 11): + from exceptiongroup import BaseExceptionGroup + @pytest.fixture def app() -> Quart: @@ -53,8 +57,10 @@ async def test_websocket_abort(app: Quart) -> None: try: async with test_client.websocket("/ws/abort/") as test_websocket: await test_websocket.receive() - except WebsocketResponseError as error: - assert error.response.status_code == 401 + except BaseExceptionGroup as error: + for exception in error.exceptions: + if isinstance(exception, WebsocketResponseError): + assert exception.response.status_code == 401 @pytest.mark.trio