Skip to content

Commit

Permalink
Merge pull request #42 from allekmott/improve-docs
Browse files Browse the repository at this point in the history
Improve Quick Start Documentation
  • Loading branch information
yunstanford committed Apr 6, 2020
2 parents d1d1a0b + f735461 commit c0f05dc
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ Install
Quick Start
-----------

You don't have to load ``pytest-sanic`` explicitly. ``pytest`` will do it for you. Just write tests like,
You don't have to load ``pytest-sanic`` explicitly. ``pytest`` will do it for you.

You can set up a fixture for your ``app`` like this:

.. code-block:: python
import pytest
from .app import create_app
@pytest.yield_fixture
def app():
app = create_app(test_config, **params)
yield app
This ``app`` fixture can then be used from tests:

.. code-block:: python
Expand All @@ -85,22 +99,18 @@ You don't have to load ``pytest-sanic`` explicitly. ``pytest`` will do it for yo
assert doc.name == "Kobe Bryant"
assert doc.team == "Lakers"
Here's much more realistic & useful example,
To send requests to your ``app``, you set up a client fixture using the loop_ and sanic_client_ fixtures:

.. code-block:: python
from .app import create_app
@pytest.yield_fixture
def app():
app = create_app(test_config, **params)
yield app
@pytest.fixture
def test_cli(loop, app, sanic_client):
return loop.run_until_complete(sanic_client(app))
This ``test_cli`` fixture can then be used to send requests to your ``app``:

.. code-block:: python
async def test_index(test_cli):
resp = await test_cli.get('/')
assert resp.status == 200
Expand All @@ -109,7 +119,6 @@ Here's much more realistic & useful example,
resp = await test_cli.get('/player')
assert resp.status == 200
--------------------
asynchronous fixture
--------------------
Expand Down

0 comments on commit c0f05dc

Please sign in to comment.