Skip to content

Commit 633c988

Browse files
committed
[Documentation] Finalizers and async fixtures. Fixes pytest-dev#59
1 parent 1ec9287 commit 633c988

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.rst

+15
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ to redefine the ``event_loop`` fixture to have the same or broader scope.
130130
Async fixtures need the event loop, and so must have the same or narrower scope
131131
than the ``event_loop`` fixture.
132132

133+
Python 3.5 lacks support for async generators. If you really need support for
134+
Python 3.5, you can still mimic a tear down using pytest's finalizers. Notice
135+
that the event loop is not running inside finalizers:
136+
137+
.. code-block:: python
138+
139+
@pytest.fixture
140+
async def async_fixture(request, event_loop):
141+
def fin():
142+
async def afin():
143+
await some_teardown()
144+
event_loop.run_until_complete(afin())
145+
request.addfinalizer(fin)
146+
return 'a value'
147+
133148
Markers
134149
-------
135150

0 commit comments

Comments
 (0)