Skip to content

Commit 1900b24

Browse files
committed
Correct and clarify async fixture docs
- Add demonstration of async_fixture (no yield). - Correct async generator fixture example to use async_yield_fixture. - Note that async_fixture and async_yield_fixture must be called.
1 parent 9662dc7 commit 1900b24

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,25 @@ async/await fixtures
111111
pytest fixture semantics of setup, value, and teardown. At present only
112112
function scope is supported.
113113

114+
Note: in pytest-twisted version 0.12, you must *call*
115+
``pytest_twisted.async_fixture`` and ``pytest_twisted.async_yield_fixture``.
116+
This restriction may be removed in a future release.
117+
114118
.. code-block:: python
115119
116-
@pytest_twisted.async_fixture
120+
# No yield (coroutine function)
121+
# -> use pytest_twisted.async_fixture()
122+
@pytest_twisted.async_fixture()
117123
async def foo():
124+
d = defer.Deferred()
125+
reactor.callLater(0.01, d.callback, 42)
126+
value = await d
127+
return value
128+
129+
# With yield (asynchronous generator)
130+
# -> use pytest_twisted.async_yield_fixture()
131+
@pytest_twisted.async_yield_fixture()
132+
async def foo_with_teardown():
118133
d1, d2 = defer.Deferred(), defer.Deferred()
119134
reactor.callLater(0.01, d1.callback, 42)
120135
reactor.callLater(0.02, d2.callback, 37)

0 commit comments

Comments
 (0)