From 6e0815a8b3d7121dfd4777387643f19c6197a741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Fri, 8 Jul 2022 15:55:00 +0200 Subject: [PATCH] Fix skipping tests requiring httptools (#1538) The test suite currently skips some tests when httptools are missing. However, there are more tests requiring it and they currently fail if that is the case. Cover them with necessary skips as well. --- tests/middleware/test_logging.py | 11 ++++++++++- tests/protocols/test_http.py | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/middleware/test_logging.py b/tests/middleware/test_logging.py index ad162e7892..1b183f85c1 100644 --- a/tests/middleware/test_logging.py +++ b/tests/middleware/test_logging.py @@ -7,6 +7,15 @@ from tests.utils import run_server from uvicorn import Config +from uvicorn.protocols.http.h11_impl import H11Protocol + +try: + from uvicorn.protocols.http.httptools_impl import HttpToolsProtocol +except ImportError: # pragma: nocover + HttpToolsProtocol = None + + +HTTP_PROTOCOLS = [p for p in [H11Protocol, HttpToolsProtocol] if p is not None] @contextlib.contextmanager @@ -49,7 +58,7 @@ async def test_trace_logging(caplog, logging_config): @pytest.mark.anyio -@pytest.mark.parametrize("http_protocol", [("h11"), ("httptools")]) +@pytest.mark.parametrize("http_protocol", HTTP_PROTOCOLS) async def test_trace_logging_on_http_protocol(http_protocol, caplog, logging_config): config = Config( app=app, diff --git a/tests/protocols/test_http.py b/tests/protocols/test_http.py index b8e3189bb0..839b09441e 100644 --- a/tests/protocols/test_http.py +++ b/tests/protocols/test_http.py @@ -766,6 +766,7 @@ async def test_invalid_http_request(request_line, protocol_cls, caplog): assert b"Invalid HTTP request received." in protocol.transport.buffer +@pytest.mark.skipif(HttpToolsProtocol is None, reason="httptools is not installed") def test_fragmentation(): def receive_all(sock): chunks = []