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 withportion of the code. - return_value is the
as client:portion - post (the
postfunction) - return_value is the invoked return value from
postso the()part of the function call.
Hopefully that makes sense!
