diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index eea97935..cfc0f832 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -271,9 +271,13 @@ def test_exception_in_ws_logged(caplog): with caplog.at_level(logging.INFO): app.test_client.websocket("/feed") - error_logs = [r for r in caplog.record_tuples if r[0] == "sanic.error"] - assert error_logs[1][1] == logging.ERROR - assert "Exception occurred while handling uri:" in error_logs[1][2] + for record in caplog.record_tuples: + if record[2].startswith("Exception occurred"): + break + + assert record[0] == "sanic.error" + assert record[1] == logging.ERROR + assert "Exception occurred while handling uri:" in record[2] @pytest.mark.parametrize("debug", (True, False)) diff --git a/tests/test_exceptions_handler.py b/tests/test_exceptions_handler.py index 9ad595fc..91411ce4 100644 --- a/tests/test_exceptions_handler.py +++ b/tests/test_exceptions_handler.py @@ -222,7 +222,7 @@ def test_single_arg_exception_handler_notice(exception_handler_app, caplog): _, response = exception_handler_app.test_client.get("/1") for record in caplog.records: - if record.message.startswith("You are"): + if record.message.startswith("You are using"): break assert record.message == ( diff --git a/tests/test_graceful_shutdown.py b/tests/test_graceful_shutdown.py index 1733ffd1..54ba92d8 100644 --- a/tests/test_graceful_shutdown.py +++ b/tests/test_graceful_shutdown.py @@ -2,7 +2,6 @@ import asyncio import logging import time -from collections import Counter from multiprocessing import Process import httpx @@ -36,11 +35,14 @@ def test_no_exceptions_when_cancel_pending_request(app, caplog): p.kill() - counter = Counter([r[1] for r in caplog.record_tuples]) - - assert counter[logging.INFO] == 11 - assert logging.ERROR not in counter - assert ( - caplog.record_tuples[9][2] - == "Request: GET http://127.0.0.1:8000/ stopped. Transport is closed." - ) + info = 0 + for record in caplog.record_tuples: + assert record[1] != logging.ERROR + if record[1] == logging.INFO: + info += 1 + if record[2].startswith("Request:"): + assert record[2] == ( + "Request: GET http://127.0.0.1:8000/ stopped. " + "Transport is closed." + ) + assert info == 11