Skip to content

Commit f97e5f1

Browse files
authored
Update README.rst
Added docs for async fixtures
1 parent 55323c8 commit f97e5f1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Features
4242
- fixtures for injecting unused tcp ports
4343
- pytest markers for treating tests as asyncio coroutines
4444
- easy testing with non-default event loops
45-
45+
- support of `async def` fixtures and async generator fixtures
4646

4747
Installation
4848
------------
@@ -122,6 +122,23 @@ when several unused TCP ports are required in a test.
122122
port1, port2 = unused_tcp_port_factory(), unused_tcp_port_factory()
123123
...
124124
125+
``async fixtures``
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127+
This fixtures may be defined as common pytest fixture:
128+
129+
.. code-block:: python
130+
131+
@pytest.fixture(scope='function')
132+
async def async_gen_fixture():
133+
yield await asyncio.sleep(0.1)
134+
135+
@pytest.fixture(scope='function')
136+
async def async_fixture():
137+
return await asyncio.sleep(0.1)
138+
139+
They behave just like a common fixtures, except that they **must** be function-scoped.
140+
That ensures that they a run in the same event loop as test function.
141+
125142
Markers
126143
-------
127144

@@ -172,6 +189,7 @@ Changelog
172189
- Using ``forbid_global_loop`` now allows tests to use ``asyncio``
173190
subprocesses.
174191
`#36 <https://github.com/pytest-dev/pytest-asyncio/issues/36>`_
192+
- support for async and async gen fixtures
175193

176194
0.5.0 (2016-09-07)
177195
~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)