### Install Async Mock Source: https://github.com/timsavage/asyncmock/blob/master/README.rst Installs the asyncmock package using pip. This command is executed in a bash terminal to add the library to your Python environment. ```bash pip install asyncmock ``` -------------------------------- ### Async Mock Exception Handling with pytest Source: https://github.com/timsavage/asyncmock/blob/master/README.rst Provides an example using pytest and pytest-asyncio to test raising an exception with AsyncMock. It configures the mock's `side_effect` to an exception and uses `pytest.raises` to verify it. ```python @pytest.mark.asyncio async def test_raise_exception(): my_mock = AsyncMock(side_effect=KeyError) with pytest.raises(KeyError): await my_mock() my_mock.assert_called() ``` -------------------------------- ### Basic Async Mock Usage Source: https://github.com/timsavage/asyncmock/blob/master/README.rst Demonstrates the basic instantiation and usage of AsyncMock. It shows how to create an instance, await a call to it, and assert that it was called with specific arguments. ```python my_mock = AsyncMock() await my_mock("foo", bar=123) my_mock.assert_called_with("foo", bar=123) ``` -------------------------------- ### Async Mock with Nested Methods Source: https://github.com/timsavage/asyncmock/blob/master/README.rst Illustrates how AsyncMock can be used with nested methods. It shows creating a mock, awaiting a call to a mocked method, and asserting the call on the nested method. ```python my_mock = AsyncMock() await my_mock.my_method("foo", bar=123) my_mock.my_method.assert_called_with("foo", bar=123) ``` -------------------------------- ### Async Mock with Non-Awaitable Return Source: https://github.com/timsavage/asyncmock/blob/master/README.rst Shows how to configure a mock method to return a non-awaitable item or to be treated as non-awaitable. The `not_async` attribute can be set to `True` on the mock or passed during initialization. ```python my_mock = AsyncMock() my_mock.my_method.not_async = True my_mock.my_method("foo", bar=123) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.