|
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 _async_pytest_fixture_setup, _async_pytest_pyfunc_call |
| 19 | +elif sys.version_info[0] == 2: |
| 20 | + from pytest_twisted.two import _async_pytest_pyfunc_call |
| 21 | + |
17 | 22 |
|
18 | 23 | class WrongReactorAlreadyInstalledError(Exception): |
19 | 24 | pass |
@@ -244,6 +249,7 @@ def _set_mark(o, mark): |
244 | 249 |
|
245 | 250 |
|
246 | 251 | def _marked_async_fixture(mark): |
| 252 | + print(pytest) |
247 | 253 | @functools.wraps(pytest.fixture) |
248 | 254 | @_optional_arguments() |
249 | 255 | def fixture(f, *args, **kwargs): |
@@ -308,39 +314,6 @@ def finalizer(): |
308 | 314 | return finalizer |
309 | 315 |
|
310 | 316 |
|
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 | | - if sys.version_info >= (3,): |
339 | | - return arg_value |
340 | | - else: |
341 | | - defer.returnValue(arg_value) |
342 | | - |
343 | | - |
344 | 317 | @defer.inlineCallbacks |
345 | 318 | def _tear_it_down(deferred): |
346 | 319 | """Tear down a specific async yield fixture.""" |
@@ -405,28 +378,6 @@ def inner_test(**kwargs): |
405 | 378 | return result |
406 | 379 |
|
407 | 380 |
|
408 | | -@defer.inlineCallbacks |
409 | | -def _async_pytest_pyfunc_call(pyfuncitem, f, kwargs): |
410 | | - """Run test function.""" |
411 | | - fixture_kwargs = { |
412 | | - name: value |
413 | | - for name, value in pyfuncitem.funcargs.items() |
414 | | - if name in pyfuncitem._fixtureinfo.argnames |
415 | | - } |
416 | | - kwargs.update(fixture_kwargs) |
417 | | - |
418 | | - maybe_mark = _get_mark(f) |
419 | | - if maybe_mark == 'async_test': |
420 | | - result = yield defer.ensureDeferred(f(**kwargs)) |
421 | | - elif maybe_mark == 'inline_callbacks_test': |
422 | | - result = yield f(**kwargs) |
423 | | - else: |
424 | | - # TODO: maybe deprecate this |
425 | | - result = yield f(**kwargs) |
426 | | - |
427 | | - return result |
428 | | - |
429 | | - |
430 | 381 | @pytest.fixture(scope="session", autouse=True) |
431 | 382 | def twisted_greenlet(): |
432 | 383 | """Provide the twisted greenlet in fixture form.""" |
|
0 commit comments