@@ -152,7 +152,7 @@ def decorator(f):
152
152
return fixture
153
153
154
154
155
- _mark_attribute_name = '_pytest_twisted_coroutine_wrapper '
155
+ _mark_attribute_name = '_pytest_twisted_mark '
156
156
async_fixture = _marked_async_fixture ('async_fixture' )
157
157
async_yield_fixture = _marked_async_fixture ('async_yield_fixture' )
158
158
@@ -164,24 +164,7 @@ def pytest_fixture_setup(fixturedef, request):
164
164
165
165
mark = maybe_mark
166
166
167
- if _instances .gr_twisted is not None :
168
- if _instances .gr_twisted .dead :
169
- raise RuntimeError ("twisted reactor has stopped" )
170
-
171
- def in_reactor (d , f , * args ):
172
- return defer .maybeDeferred (f , * args ).chainDeferred (d )
173
-
174
- d = defer .Deferred ()
175
- _instances .reactor .callLater (
176
- 0.0 , in_reactor , d , _pytest_fixture_setup , fixturedef , request , mark
177
- )
178
- blockon_default (d )
179
- else :
180
- if not _instances .reactor .running :
181
- raise RuntimeError ("twisted reactor is not running" )
182
- blockingCallFromThread (
183
- _instances .reactor , _pytest_fixture_setup , fixturedef , request , mark
184
- )
167
+ run_inline_callbacks (_pytest_fixture_setup , fixturedef , request , mark )
185
168
186
169
return True
187
170
@@ -252,31 +235,30 @@ def tear_it_down(deferred):
252
235
# claims it should also take a nextItem but that triggers a direct error
253
236
254
237
238
+ def run_inline_callbacks (f , * args ):
239
+ if _instances .gr_twisted is not None :
240
+ if _instances .gr_twisted .dead :
241
+ raise RuntimeError ("twisted reactor has stopped" )
242
+
243
+ def in_reactor (d , f , * args ):
244
+ return defer .maybeDeferred (f , * args ).chainDeferred (d )
245
+
246
+ d = defer .Deferred ()
247
+ _instances .reactor .callLater (0.0 , in_reactor , d , f , * args )
248
+ blockon_default (d )
249
+ else :
250
+ if not _instances .reactor .running :
251
+ raise RuntimeError ("twisted reactor is not running" )
252
+ blockingCallFromThread (_instances .reactor , f , * args )
253
+
254
+
255
255
@pytest .hookimpl (hookwrapper = True )
256
256
def pytest_runtest_teardown (item ):
257
257
yield
258
258
259
259
while len (to_be_torn_down ) > 0 :
260
260
deferred = to_be_torn_down .pop (0 )
261
- if _instances .gr_twisted is not None :
262
- if _instances .gr_twisted .dead :
263
- raise RuntimeError ("twisted reactor has stopped" )
264
-
265
- def in_reactor (d , f , * args ):
266
- # return f.chainDeferred(d)
267
- return defer .maybeDeferred (f , * args ).chainDeferred (d )
268
-
269
- d = defer .Deferred ()
270
- _instances .reactor .callLater (
271
- 0.0 , in_reactor , d , tear_it_down , deferred
272
- )
273
- blockon_default (d )
274
- else :
275
- if not _instances .reactor .running :
276
- raise RuntimeError ("twisted reactor is not running" )
277
- blockingCallFromThread (
278
- _instances .reactor , tear_it_down , deferred ,
279
- )
261
+ run_inline_callbacks (tear_it_down , deferred )
280
262
281
263
282
264
@defer .inlineCallbacks
@@ -287,24 +269,7 @@ def _pytest_pyfunc_call(pyfuncitem):
287
269
288
270
289
271
def pytest_pyfunc_call (pyfuncitem ):
290
- if _instances .gr_twisted is not None :
291
- if _instances .gr_twisted .dead :
292
- raise RuntimeError ("twisted reactor has stopped" )
293
-
294
- def in_reactor (d , f , * args ):
295
- return defer .maybeDeferred (f , * args ).chainDeferred (d )
296
-
297
- d = defer .Deferred ()
298
- _instances .reactor .callLater (
299
- 0.0 , in_reactor , d , _pytest_pyfunc_call , pyfuncitem
300
- )
301
- blockon_default (d )
302
- else :
303
- if not _instances .reactor .running :
304
- raise RuntimeError ("twisted reactor is not running" )
305
- blockingCallFromThread (
306
- _instances .reactor , _pytest_pyfunc_call , pyfuncitem
307
- )
272
+ run_inline_callbacks (_pytest_pyfunc_call , pyfuncitem )
308
273
return True
309
274
310
275
0 commit comments