diff --git a/sanic/app.py b/sanic/app.py index fe6d2708..753f477b 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -86,6 +86,7 @@ class Sanic: self.websocket_tasks: Set[Future] = set() self.named_request_middleware: Dict[str, MiddlewareType] = {} self.named_response_middleware: Dict[str, MiddlewareType] = {} + self._test_manager = None self._test_client = None self._asgi_client = None # Register alternative method names @@ -1032,18 +1033,22 @@ class Sanic: # -------------------------------------------------------------------- # @property - def test_client(self): + def test_client(self): # noqa if self._test_client: return self._test_client + elif self._test_manager: + return self._test_manager.test_client from sanic_testing.testing import SanicTestClient # type: ignore self._test_client = SanicTestClient(self) return self._test_client @property - def asgi_client(self): + def asgi_client(self): # noqa if self._asgi_client: return self._asgi_client + elif self._test_manager: + return self._test_manager.test_client from sanic_testing.testing import SanicASGITestClient # type: ignore self._asgi_client = SanicASGITestClient(self) diff --git a/tests/test_static.py b/tests/test_static.py index 23ba05d7..78c114b9 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -1,5 +1,6 @@ import inspect import os + from pathlib import Path from time import gmtime, strftime @@ -93,8 +94,8 @@ def test_static_file_pathlib(app, static_file_directory, file_name): [b"test.file", b"decode me.txt", b"python.png"], ) def test_static_file_bytes(app, static_file_directory, file_name): - bsep = os.path.sep.encode('utf-8') - file_path = static_file_directory.encode('utf-8') + bsep + file_name + bsep = os.path.sep.encode("utf-8") + file_path = static_file_directory.encode("utf-8") + bsep + file_name app.static("/testing.file", file_path) request, response = app.test_client.get("/testing.file") assert response.status == 200