Extension to the standard mock framework to support support async
Awaitable mocks for async code.
The package specifically only extends mock and not any other part of unittest.
Mock 4.0+ (included within Python 3.8+) now includes an awaitable mock mock.AsyncMock. This is recommended for new projects.
Install using pip:
pip install asyncmock
Async Mock is a drop in replacement for a Mock object eg:
my_mock = AsyncMock() await my_mock("foo", bar=123) my_mock.assert_called_with("foo", bar=123)
This also works with nested methods:
my_mock = AsyncMock() await my_mock.my_method("foo", bar=123) my_mock.my_method.assert_called_with("foo", bar=123)
Side effects and return values can also be awaited.
Including a non-awaitable item:
my_mock = AsyncMock() my_mock.my_method.not_async = True my_mock.my_method("foo", bar=123)
The not_async option can also be provided as an init argument. The not_async argument is not inherited by sub-mocks.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for asyncmock-0.4.2-py3-none-any.whl