Skip to content

Commit d8848dd

Browse files
f0t0nasvetlov
authored andcommitted
Document test_utils.make_mocked_coro function (#1113)
1 parent 03ca4a3 commit d8848dd

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

aiohttp/test_utils.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,16 +381,7 @@ def make_mocked_request(method, path, headers=None, *,
381381

382382

383383
def make_mocked_coro(return_value):
384-
"""A coroutine mock.
385-
386-
Behavees like a coroutine which returns return_value.
387-
388-
But it is also a mock object, you might test it as usual Mock:
389-
390-
mocked = mocke_mocked_coro(1)
391-
assert 1 == await mocked(1, 2)
392-
mocked.assert_called_with(1, 2)
393-
"""
384+
"""Creates a coroutine mock."""
394385
@asyncio.coroutine
395386
def mock_coro(*args, **kwargs):
396387
return return_value

docs/testing.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,23 @@ aiohttp.test_utils
447447
:undoc-members:
448448
:show-inheritance:
449449

450+
.. function:: make_mocked_coro(return_value)
451+
452+
Creates a coroutine mock.
453+
454+
Behaves like a coroutine which returns `return_value`.
455+
But it is also a mock object, you might test it as usual Mock::
456+
457+
mocked = make_mocked_coro(1)
458+
assert 1 == await mocked(1, 2)
459+
mocked.assert_called_with(1, 2)
460+
461+
462+
:param return_value: A value that the the mock object will return when
463+
called.
464+
:returns: A mock object that behaves as a coroutine which returns
465+
`return_value` when called.
466+
450467

451468
.. _pytest: http://pytest.org/latest/
452469
.. _pytest-aiohttp: https://pypi.python.org/pypi/pytest-aiohttp

0 commit comments

Comments
 (0)