From 6563ee28bfa61f66040de2d550406ee176f26d94 Mon Sep 17 00:00:00 2001 From: prryplatypus <25409753+prryplatypus@users.noreply.github.com> Date: Sat, 23 Oct 2021 21:16:49 +0200 Subject: [PATCH] Fix tests (hopefully?) --- tests/test_exceptions.py | 18 ++++++------------ tests/test_exceptions_handler.py | 6 ++++-- tests/test_graceful_shutdown.py | 6 +++--- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 503e47cb..041766a5 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -4,7 +4,6 @@ import warnings import pytest from bs4 import BeautifulSoup -from websockets.version import version as websockets_version from sanic import Sanic from sanic.exceptions import ( @@ -260,15 +259,10 @@ def test_exception_in_ws_logged(caplog): raise Exception("...") with caplog.at_level(logging.INFO): - app.test_client.websocket("/feed") - # Websockets v10.0 and above output an additional - # INFO message when a ws connection is accepted - ws_version_parts = websockets_version.split(".") - ws_major = int(ws_version_parts[0]) - record_index = 2 if ws_major >= 10 else 1 - assert caplog.record_tuples[record_index][0] == "sanic.error" - assert caplog.record_tuples[record_index][1] == logging.ERROR + req, _ = app.test_client.websocket("/feed") + assert ( - "Exception occurred while handling uri:" - in caplog.record_tuples[record_index][2] - ) + "sanic.error", + logging.ERROR, + "Exception occurred while handling uri: %s" % repr(req.url) + ) in caplog.record_tuples diff --git a/tests/test_exceptions_handler.py b/tests/test_exceptions_handler.py index 9bedf7e6..e5b8fb8c 100644 --- a/tests/test_exceptions_handler.py +++ b/tests/test_exceptions_handler.py @@ -219,11 +219,13 @@ def test_single_arg_exception_handler_notice(exception_handler_app, caplog): with caplog.at_level(logging.WARNING): _, response = exception_handler_app.test_client.get("/1") - assert caplog.records[0].message == ( + assert ( + "sanic.error", + logging.WARNING, "You are using a deprecated error handler. The lookup method should " "accept two positional parameters: (exception, route_name: " "Optional[str]). Until you upgrade your ErrorHandler.lookup, " "Blueprint specific exceptions will not work properly. Beginning in " "v22.3, the legacy style lookup method will not work at all." - ) + ) in caplog.record_tuples assert response.status == 400 diff --git a/tests/test_graceful_shutdown.py b/tests/test_graceful_shutdown.py index 8380ed50..a2e3bb79 100644 --- a/tests/test_graceful_shutdown.py +++ b/tests/test_graceful_shutdown.py @@ -40,7 +40,7 @@ def test_no_exceptions_when_cancel_pending_request(app, caplog): assert counter[logging.INFO] == 5 assert logging.ERROR not in counter - assert ( - caplog.record_tuples[3][2] - == "Request: GET http://127.0.0.1:8000/ stopped. Transport is closed." + assert any( + r[2] == "Request: GET http://127.0.0.1:8000/ stopped. Transport is closed." + for r in caplog.record_tuples )