Skip to content

Commit

Permalink
Document test_utils.make_mocked_coro function (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
f0t0n authored and asvetlov committed Aug 24, 2016
1 parent 03ca4a3 commit d8848dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 1 addition & 10 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,7 @@ def make_mocked_request(method, path, headers=None, *,


def make_mocked_coro(return_value):
"""A coroutine mock.
Behavees like a coroutine which returns return_value.
But it is also a mock object, you might test it as usual Mock:
mocked = mocke_mocked_coro(1)
assert 1 == await mocked(1, 2)
mocked.assert_called_with(1, 2)
"""
"""Creates a coroutine mock."""
@asyncio.coroutine
def mock_coro(*args, **kwargs):
return return_value
Expand Down
17 changes: 17 additions & 0 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,23 @@ aiohttp.test_utils
:undoc-members:
:show-inheritance:

.. function:: make_mocked_coro(return_value)

Creates a coroutine mock.

Behaves like a coroutine which returns `return_value`.
But it is also a mock object, you might test it as usual Mock::

mocked = make_mocked_coro(1)
assert 1 == await mocked(1, 2)
mocked.assert_called_with(1, 2)


:param return_value: A value that the the mock object will return when
called.
:returns: A mock object that behaves as a coroutine which returns
`return_value` when called.


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

0 comments on commit d8848dd

Please sign in to comment.