Skip to content

Commit 37616a6

Browse files
authored
Merge pull request #77 from cdunklau/fix-async-fixture-docs
Correct and clarify async fixture docs
2 parents 9662dc7 + 8d9f6b3 commit 37616a6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
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: You must *call* ``pytest_twisted.async_fixture()`` and
115+
``pytest_twisted.async_yield_fixture()``.
116+
This requirement 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)

pytest_twisted.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AsyncFixtureUnsupportedScopeError(Exception):
3535
@classmethod
3636
def from_scope(cls, scope):
3737
return cls(
38-
'Unsupported scope used for async fixture: {}'.format(scope)
38+
'Unsupported scope {0!r} used for async fixture'.format(scope)
3939
)
4040

4141

0 commit comments

Comments
 (0)