From 050a563e1d5b0bba6f5e037152ef3229b3fe52be Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Thu, 9 Jul 2020 14:57:42 +0300 Subject: [PATCH] Add documentation on test mode --- docs/sanic/testing.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/sanic/testing.rst b/docs/sanic/testing.rst index 67506edc..9e47657c 100644 --- a/docs/sanic/testing.rst +++ b/docs/sanic/testing.rst @@ -58,6 +58,22 @@ More information about the available arguments to `httpx` can be found [in the documentation for `httpx `_. +Additionally, Sanic has an asynchronous testing client. The difference is that the async client will not stand up an +instance of your application, but will instead reach inside it using ASGI. All listeners and middleware are still +executed. + +.. code-block:: python + + @pytest.mark.asyncio + async def test_index_returns_200(): + request, response = await app.asgi_client.put('/') + assert response.status == 200 + +.. note:: + + Whenever one of the test clients run, you can test your app instance to determine if it is in testing mode: + `app.test_mode`. + Using a random port -------------------