Fix tests (hopefully?)

This commit is contained in:
prryplatypus 2021-10-23 21:16:49 +02:00
parent 250c5cf60d
commit 6563ee28bf
No known key found for this signature in database
GPG Key ID: 6687E128FB70819B
3 changed files with 13 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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
)