{"id":13705463,"url":"https://github.com/sanic-org/sanic-testing","last_synced_at":"2025-07-21T17:33:27.757Z","repository":{"id":37989514,"uuid":"263834962","full_name":"sanic-org/sanic-testing","owner":"sanic-org","description":"Test clients for Sanic","archived":false,"fork":false,"pushed_at":"2024-06-30T12:12:38.000Z","size":113,"stargazers_count":32,"open_issues_count":10,"forks_count":21,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-07-15T03:25:29.759Z","etag":null,"topics":["hacktoberfest","python","sanic","testing"],"latest_commit_sha":null,"homepage":"https://sanic.dev/en/plugins/sanic-testing/getting-started.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sanic-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-14T06:34:14.000Z","updated_at":"2024-12-10T23:02:27.000Z","dependencies_parsed_at":"2024-01-07T00:08:12.046Z","dependency_job_id":"9016640d-8771-4245-bfda-0aa1df7b3d27","html_url":"https://github.com/sanic-org/sanic-testing","commit_stats":{"total_commits":91,"total_committers":14,"mean_commits":6.5,"dds":0.5164835164835164,"last_synced_commit":"6e632cc2c1d058f192fd46360c2c312690c45b9c"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/sanic-org/sanic-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanic-org%2Fsanic-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanic-org%2Fsanic-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanic-org%2Fsanic-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanic-org%2Fsanic-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanic-org","download_url":"https://codeload.github.com/sanic-org/sanic-testing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanic-org%2Fsanic-testing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266342809,"owners_count":23914262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","python","sanic","testing"],"created_at":"2024-08-02T22:00:41.942Z","updated_at":"2025-07-21T17:33:27.727Z","avatar_url":"https://github.com/sanic-org.png","language":"Python","funding_links":[],"categories":["Extensions"],"sub_categories":["Official"],"readme":"# Sanic Core Test\n\nThis package is meant to be the core testing utility and clients for testing Sanic applications. It is mainly derived from `sanic.testing` which has (or will be) removed from the main Sanic repository in the future.\n\n[Documentation](https://sanicframework.org/en/plugins/sanic-testing/getting-started.html)\n\n## Getting Started\n\n    pip install sanic-testing\n\nThe package is meant to create an almost seemless transition. Therefore, after loading the package, it will attach itself to your Sanic instance and insert test clients.\n\n```python\nfrom sanic import Sanic\nfrom sanic_testing import TestManager\n\nsanic_app = Sanic(__name__)\nTestManager(sanic_app)\n```\n\nThis will provide access to both the sync (`sanic.test_client`) and async (`sanic.asgi_client`) clients. Both of these clients are also available directly on the `TestManager` instance.\n\n## Writing a sync test\n\nTesting should be pretty much the same as when the test client was inside Sanic core. The difference is just that you need to run `TestManager`.\n\n```python\nimport pytest\n\n@pytest.fixture\ndef app():\n    sanic_app = Sanic(__name__)\n    TestManager(sanic_app)\n\n    @sanic_app.get(\"/\")\n    def basic(request):\n        return response.text(\"foo\")\n\n    return sanic_app\n\ndef test_basic_test_client(app):\n    request, response = app.test_client.get(\"/\")\n\n    assert response.body == b\"foo\"\n    assert response.status == 200\n```\n\n## Writing an async test\n\nTesting of an async method is best done with `pytest-asyncio` installed. Again, the following test should look familiar to anyone that has used `asgi_client` in the Sanic core package before.\n\nThe main benefit of using the `asgi_client` is that it is able to reach inside your application, and execute your handlers without ever having to stand up a server or make a network call.\n\n```python\nimport pytest\n\n@pytest.fixture\ndef app():\n    sanic_app = Sanic(__name__)\n    TestManager(sanic_app)\n\n    @sanic_app.get(\"/\")\n    def basic(request):\n        return response.text(\"foo\")\n\n    return sanic_app\n\n@pytest.mark.asyncio\nasync def test_basic_asgi_client(app):\n    request, response = await app.asgi_client.get(\"/\")\n\n    assert response.body == b\"foo\"\n    assert response.status == 200\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanic-org%2Fsanic-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanic-org%2Fsanic-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanic-org%2Fsanic-testing/lists"}