Mocking the Post Method on an Async HTTPX Post Request
A quick snippet for mocking HTTP requests with an the async httpx context manager.
= await
Quick and simple post for getting at the method that you want to patch
. # The client to patch
=
- mock_httpx_client (The patched uninitialised class of
httpx.AsyncClient
) - return_value (The class that is returned when initialised) this is the
()
- aenter is the
async with
portion of the code. - return_value is the
as client:
portion - post (the
post
function) - return_value is the invoked return value from
post
so the()
part of the function call.
Hopefully that makes sense!