MCPcopy
hub / github.com/scrapy/scrapy / inline_callbacks_test

Function inline_callbacks_test

tests/utils/decorators.py:19–48  ·  view source on GitHub ↗

Mark a test function written in a :func:`twisted.internet.defer.inlineCallbacks` style. This calls :func:`twisted.internet.defer.inlineCallbacks` and then: * with ``pytest-twisted`` this returns the resulting Deferred * with ``pytest-asyncio`` this converts the resulting Deferred into

(
    f: Callable[_P, Generator[Deferred[Any], Any, None]],
)

Source from the content-addressed store, hash-verified

17
18
19def inline_callbacks_test(
20 f: Callable[_P, Generator[Deferred[Any], Any, None]],
21) -> Callable[_P, Awaitable[None]]:
22 """Mark a test function written in a :func:`twisted.internet.defer.inlineCallbacks` style.
23
24 This calls :func:`twisted.internet.defer.inlineCallbacks` and then:
25
26 * with ``pytest-twisted`` this returns the resulting Deferred
27 * with ``pytest-asyncio`` this converts the resulting Deferred into a
28 coroutine
29 """
30
31 if not is_reactor_installed():
32
33 @pytest.mark.asyncio
34 @wraps(f)
35 async def wrapper_coro(*args: _P.args, **kwargs: _P.kwargs) -> None:
36 await deferred_to_future(inlineCallbacks(f)(*args, **kwargs))
37
38 # Likely https://github.com/python/mypy/issues/17171
39 return wrapper_coro # type: ignore[no-any-return]
40
41 @wraps(f)
42 @inlineCallbacks
43 def wrapper_dfd(
44 *args: _P.args, **kwargs: _P.kwargs
45 ) -> Generator[Deferred[Any], Any, None]:
46 return f(*args, **kwargs)
47
48 return wrapper_dfd
49
50
51def coroutine_test(

Callers

nothing calls this directly

Calls 1

is_reactor_installedFunction · 0.90

Tested by

no test coverage detected