diff --git a/docs/sanic/extensions.md b/docs/sanic/extensions.md index da49da89..92b61f8c 100644 --- a/docs/sanic/extensions.md +++ b/docs/sanic/extensions.md @@ -23,3 +23,4 @@ A list of Sanic extensions created by the community. - [sanic-prometheus](https://github.com/dkruchinin/sanic-prometheus): Prometheus metrics for Sanic - [Sanic-RestPlus](https://github.com/ashleysommer/sanic-restplus): A port of Flask-RestPlus for Sanic. Full-featured REST API with SwaggerUI generation. - [sanic-transmute](https://github.com/yunstanford/sanic-transmute): A Sanic extension that generates APIs from python function and classes, and also generates Swagger UI/documentation automatically. +- [pytest-sanic](https://github.com/yunstanford/pytest-sanic): A pytest plugin for Sanic. It helps you to test your code asynchronously. diff --git a/docs/sanic/testing.md b/docs/sanic/testing.md index d4f61b4c..58c98858 100644 --- a/docs/sanic/testing.md +++ b/docs/sanic/testing.md @@ -57,3 +57,24 @@ def test_post_json_request_includes_data(): More information about the available arguments to aiohttp can be found [in the documentation for ClientSession](https://aiohttp.readthedocs.io/en/stable/client_reference.html#client-session). + + +# pytest-sanic + +[pytest-sanic](https://github.com/yunstanford/pytest-sanic) is a pytest plugin, it helps you to test your code asynchronously. +Just write tests like, + +```python + async def test_sanic_db_find_by_id(app): + """ + Let's assume that, in db we have, + { + "id": "123", + "name": "Kobe Bryant", + "team": "Lakers", + } + """ + doc = await app.db["players"].find_by_id("123") + assert doc.name == "Kobe Bryant" + assert doc.team == "Lakers" +```