Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
Catch and extract from ExceptionGroups
  • Loading branch information
pgjones committed May 19, 2024
1 parent 4e68dd7 commit 805686a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 9 additions & 5 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import NoReturn
import sys
from typing import NoReturn

import pytest
from quart import ResponseReturnValue
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from pathlib import Path

import pytest
Expand All @@ -6,6 +7,9 @@

from quart_trio import QuartTrio

if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup


@pytest.fixture
def app() -> Quart:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 805686a

Please sign in to comment.