Skip to content

Commit 1740c99

Browse files
authored
Add an xfailing test expecting HTTP500 for invalid handler return values
PR #4574 by @Fogapod This change documents a contract of disallowing non-response return values in request handlers that currently has a bug and is therefore marked as xfail. Ref: #4572
1 parent f80029b commit 1740c99

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_web_request.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from yarl import URL
1111

1212
from aiohttp import HttpVersion, web
13+
from aiohttp.client_exceptions import ServerDisconnectedError
1314
from aiohttp.helpers import DEBUG
1415
from aiohttp.http_parser import RawRequestMessage
1516
from aiohttp.streams import StreamReader
@@ -771,3 +772,19 @@ async def handler(request):
771772
def test_weakref_creation() -> None:
772773
req = make_mocked_request('GET', '/')
773774
weakref.ref(req)
775+
776+
777+
@pytest.mark.xfail(
778+
raises=ServerDisconnectedError,
779+
reason="see https://github.com/aio-libs/aiohttp/issues/4572"
780+
)
781+
async def test_handler_return_type(aiohttp_client) -> None:
782+
async def invalid_handler_1(request):
783+
return 1
784+
785+
app = web.Application()
786+
app.router.add_get('/1', invalid_handler_1)
787+
client = await aiohttp_client(app)
788+
789+
async with client.get('/1') as resp:
790+
assert 500 == resp.status

0 commit comments

Comments
 (0)