File tree 2 files changed +17
-2
lines changed
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -111,10 +111,25 @@ async/await fixtures
111
111
pytest fixture semantics of setup, value, and teardown. At present only
112
112
function scope is supported.
113
113
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
+
114
118
.. code-block :: python
115
119
116
- @pytest_twisted.async_fixture
120
+ # No yield (coroutine function)
121
+ # -> use pytest_twisted.async_fixture()
122
+ @pytest_twisted.async_fixture ()
117
123
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 ():
118
133
d1, d2 = defer.Deferred(), defer.Deferred()
119
134
reactor.callLater(0.01 , d1.callback, 42 )
120
135
reactor.callLater(0.02 , d2.callback, 37 )
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ class AsyncFixtureUnsupportedScopeError(Exception):
35
35
@classmethod
36
36
def from_scope (cls , scope ):
37
37
return cls (
38
- 'Unsupported scope used for async fixture: {} ' .format (scope )
38
+ 'Unsupported scope {0!r} used for async fixture' .format (scope )
39
39
)
40
40
41
41
You can’t perform that action at this time.
0 commit comments