diff --git a/sanic/app.py b/sanic/app.py index f8b02ef8..eb702b5d 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -1450,7 +1450,7 @@ class Sanic: pass finally: self.websocket_tasks.remove(fut) - await ws.close() + await ws.close() # -------------------------------------------------------------------- # # ASGI diff --git a/tests/conftest.py b/tests/conftest.py index 46dddf01..96e513b8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,6 +19,11 @@ if sys.platform in ["win32", "cygwin"]: collect_ignore = ["test_worker.py"] +@pytest.fixture +def caplog(caplog): + yield caplog + + async def _handler(request): """ Dummy placeholder method used for route resolver when creating a new diff --git a/tests/test_asgi.py b/tests/test_asgi.py index 0c728493..92bc2fdc 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -41,8 +41,7 @@ def transport(message_stack, receive, send): @pytest.fixture -# @pytest.mark.asyncio -def protocol(transport, loop): +def protocol(transport): return transport.get_protocol() diff --git a/tests/test_logging.py b/tests/test_logging.py index f5a24f08..ea02b946 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -35,6 +35,7 @@ def test_log(app): logging.basicConfig( format=logging_format, level=logging.DEBUG, stream=log_stream ) + logging.getLogger("asyncio").setLevel(logging.WARNING) log = logging.getLogger() rand_string = str(uuid.uuid4()) diff --git a/tests/test_routes.py b/tests/test_routes.py index 73809518..f980411c 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -480,21 +480,21 @@ def test_websocket_route_with_subprotocols(app): results.append(ws.subprotocol) assert ws.subprotocol is not None - request, response = app.test_client.websocket("/ws", subprotocols=["bar"]) + _, response = SanicTestClient(app).websocket("/ws", subprotocols=["bar"]) assert response.opened is True assert results == ["bar"] - request, response = app.test_client.websocket( + _, response = SanicTestClient(app).websocket( "/ws", subprotocols=["bar", "foo"] ) assert response.opened is True assert results == ["bar", "bar"] - request, response = app.test_client.websocket("/ws", subprotocols=["baz"]) + _, response = SanicTestClient(app).websocket("/ws", subprotocols=["baz"]) assert response.opened is True assert results == ["bar", "bar", None] - request, response = app.test_client.websocket("/ws") + _, response = SanicTestClient(app).websocket("/ws") assert response.opened is True assert results == ["bar", "bar", None, None] diff --git a/tests/test_url_for.py b/tests/test_url_for.py index 2d692f2e..9ebe979a 100644 --- a/tests/test_url_for.py +++ b/tests/test_url_for.py @@ -1,5 +1,7 @@ import asyncio +from sanic_testing.testing import SanicTestClient + from sanic.blueprints import Blueprint @@ -48,14 +50,14 @@ def test_websocket_bp_route_name(app): uri = app.url_for("test_bp.test_route") assert uri == "/bp/route" - request, response = app.test_client.websocket(uri) + request, response = SanicTestClient(app).websocket(uri) assert response.opened is True assert event.is_set() event.clear() uri = app.url_for("test_bp.test_route2") assert uri == "/bp/route2" - request, response = app.test_client.websocket(uri) + request, response = SanicTestClient(app).websocket(uri) assert response.opened is True assert event.is_set() diff --git a/tox.ini b/tox.ini index 6ead9ae8..04dec3c9 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ setenv = {py36,py37,py38,py39,pyNightly}-no-ext: SANIC_NO_UJSON=1 {py36,py37,py38,py39,pyNightly}-no-ext: SANIC_NO_UVLOOP=1 deps = - sanic-testing + sanic-testing==0.1.2 coverage==5.3 pytest==5.2.1 pytest-cov