{"library":"sanic-testing","title":"Sanic Testing","description":"Sanic Testing provides core testing utilities and clients for Sanic applications. This package externalizes the testing functionality previously integrated directly into the main Sanic framework. It is actively maintained, with releases typically aligning with the Sanic release cycle. The current version is 24.6.0.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install sanic-testing"],"cli":null},"imports":["from sanic_testing import TestManager","from sanic_testing.testing import SanicTestClient"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pytest\nfrom sanic import Sanic, response\nfrom sanic_testing import TestManager\n\n@pytest.fixture\ndef app():\n    sanic_app = Sanic(\"TestSanic\")\n    TestManager(sanic_app) # Attaches test clients to the app instance\n\n    @sanic_app.get(\"/\")\n    async def basic(request):\n        return response.text(\"foo\")\n\n    return sanic_app\n\ndef test_basic_sync_client(app):\n    # Use the sync test client available via app.test_client\n    request, response = app.test_client.get(\"/\")\n    assert request.method.lower() == \"get\"\n    assert response.body == b\"foo\"\n    assert response.status == 200\n\n@pytest.mark.asyncio\nasync def test_basic_asgi_client(app):\n    # Use the async ASGI client available via app.asgi_client\n    request, response = await app.asgi_client.get(\"/\")\n    assert request.method.lower() == \"get\"\n    assert response.body == b\"foo\"\n    assert response.status == 200","lang":"python","description":"This quickstart demonstrates how to set up a Sanic application for testing with `sanic-testing` using `pytest`. It shows both the synchronous `app.test_client` and the asynchronous `app.asgi_client` for making requests against your Sanic application. Remember to install `pytest-asyncio` for async tests.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}