From 1740c99159176344b02006446b4302d0f92f9ac2 Mon Sep 17 00:00:00 2001 From: Eugene Date: Fri, 14 Feb 2020 03:00:00 +0300 Subject: [PATCH] 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: https://github.com/aio-libs/aiohttp/issues/4572 --- tests/test_web_request.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_web_request.py b/tests/test_web_request.py index bc352276476..f84ece582ce 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -10,6 +10,7 @@ from yarl import URL from aiohttp import HttpVersion, web +from aiohttp.client_exceptions import ServerDisconnectedError from aiohttp.helpers import DEBUG from aiohttp.http_parser import RawRequestMessage from aiohttp.streams import StreamReader @@ -771,3 +772,19 @@ async def handler(request): def test_weakref_creation() -> None: req = make_mocked_request('GET', '/') weakref.ref(req) + + +@pytest.mark.xfail( + raises=ServerDisconnectedError, + reason="see https://github.com/aio-libs/aiohttp/issues/4572" +) +async def test_handler_return_type(aiohttp_client) -> None: + async def invalid_handler_1(request): + return 1 + + app = web.Application() + app.router.add_get('/1', invalid_handler_1) + client = await aiohttp_client(app) + + async with client.get('/1') as resp: + assert 500 == resp.status