MockVWS._wrap_callback in src/mock_vws/decorators.py and _make_respx_callback in src/mock_vws/_respx_mock_server/decorators.py simulate a slow server and raise the correct client-side timeout for both requests and httpx. Neither responses nor respx supports this, so anyone testing client timeout handling today either monkeypatches or runs a real slow server.
Getting it right needs knowledge which is not discoverable from the libraries' documentation:
responses attaches req_kwargs to PreparedRequest dynamically, so it is absent from the requests type stubs.
requests accepts the timeout as a (connect, read) tuple, and only the read leg is meaningful for a server which is slow to respond.
httpx puts the equivalent in request.extensions["timeout"].
- Each needs a different exception raised:
requests.exceptions.Timeout and httpx.ReadTimeout.
The injectable sleep_fn is also part of the value, because it lets callers control virtual time instead of really sleeping.
This built on #2884, #2919 and #2974. Closing this means the code moves to its own package and this repository depends on it.
MockVWS._wrap_callbackinsrc/mock_vws/decorators.pyand_make_respx_callbackinsrc/mock_vws/_respx_mock_server/decorators.pysimulate a slow server and raise the correct client-side timeout for bothrequestsandhttpx. Neitherresponsesnorrespxsupports this, so anyone testing client timeout handling today either monkeypatches or runs a real slow server.Getting it right needs knowledge which is not discoverable from the libraries' documentation:
responsesattachesreq_kwargstoPreparedRequestdynamically, so it is absent from therequeststype stubs.requestsaccepts the timeout as a(connect, read)tuple, and only the read leg is meaningful for a server which is slow to respond.httpxputs the equivalent inrequest.extensions["timeout"].requests.exceptions.Timeoutandhttpx.ReadTimeout.The injectable
sleep_fnis also part of the value, because it lets callers control virtual time instead of really sleeping.This built on #2884, #2919 and #2974. Closing this means the code moves to its own package and this repository depends on it.