|
14 | 14 | from twisted.internet.threads import blockingCallFromThread |
15 | 15 | from twisted.python import failure |
16 | 16 |
|
| 17 | +if sys.version_info[0] == 3: |
| 18 | + from pytest_twisted.three import ( |
| 19 | + _async_pytest_fixture_setup, |
| 20 | + _async_pytest_pyfunc_call, |
| 21 | + ) |
| 22 | +elif sys.version_info[0] == 2: |
| 23 | + from pytest_twisted.two import _async_pytest_pyfunc_call |
| 24 | + |
17 | 25 |
|
18 | 26 | class WrongReactorAlreadyInstalledError(Exception): |
19 | 27 | pass |
@@ -308,36 +316,6 @@ def finalizer(): |
308 | 316 | return finalizer |
309 | 317 |
|
310 | 318 |
|
311 | | -@defer.inlineCallbacks |
312 | | -def _async_pytest_fixture_setup(fixturedef, request, mark): |
313 | | - """Setup an async or async yield fixture.""" |
314 | | - fixture_function = fixturedef.func |
315 | | - |
316 | | - kwargs = { |
317 | | - name: request.getfixturevalue(name) |
318 | | - for name in fixturedef.argnames |
319 | | - } |
320 | | - |
321 | | - if mark == 'async_fixture': |
322 | | - arg_value = yield defer.ensureDeferred( |
323 | | - fixture_function(**kwargs) |
324 | | - ) |
325 | | - elif mark == 'async_yield_fixture': |
326 | | - coroutine = fixture_function(**kwargs) |
327 | | - |
328 | | - request.addfinalizer( |
329 | | - _create_async_yield_fixture_finalizer(coroutine=coroutine), |
330 | | - ) |
331 | | - |
332 | | - arg_value = yield defer.ensureDeferred(coroutine.__anext__()) |
333 | | - else: |
334 | | - raise UnrecognizedCoroutineMarkError.from_mark(mark=mark) |
335 | | - |
336 | | - fixturedef.cached_result = (arg_value, fixturedef.cache_key(request), None) |
337 | | - |
338 | | - defer.returnValue(arg_value) |
339 | | - |
340 | | - |
341 | 319 | @defer.inlineCallbacks |
342 | 320 | def _tear_it_down(deferred): |
343 | 321 | """Tear down a specific async yield fixture.""" |
@@ -402,28 +380,6 @@ def inner_test(**kwargs): |
402 | 380 | return result |
403 | 381 |
|
404 | 382 |
|
405 | | -@defer.inlineCallbacks |
406 | | -def _async_pytest_pyfunc_call(pyfuncitem, f, kwargs): |
407 | | - """Run test function.""" |
408 | | - fixture_kwargs = { |
409 | | - name: value |
410 | | - for name, value in pyfuncitem.funcargs.items() |
411 | | - if name in pyfuncitem._fixtureinfo.argnames |
412 | | - } |
413 | | - kwargs.update(fixture_kwargs) |
414 | | - |
415 | | - maybe_mark = _get_mark(f) |
416 | | - if maybe_mark == 'async_test': |
417 | | - result = yield defer.ensureDeferred(f(**kwargs)) |
418 | | - elif maybe_mark == 'inline_callbacks_test': |
419 | | - result = yield f(**kwargs) |
420 | | - else: |
421 | | - # TODO: maybe deprecate this |
422 | | - result = yield f(**kwargs) |
423 | | - |
424 | | - defer.returnValue(result) |
425 | | - |
426 | | - |
427 | 383 | @pytest.fixture(scope="session", autouse=True) |
428 | 384 | def twisted_greenlet(): |
429 | 385 | """Provide the twisted greenlet in fixture form.""" |
|
0 commit comments