1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
From 805686abfd9963be26d59d9da9b11faddd583d11 Mon Sep 17 00:00:00 2001
From: pgjones <philip.graham.jones@googlemail.com>
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
|