Using the HTTPretty library for Python, I can create a response of optional HTTP responses and then pick them up, that is, using the library requests it as follows:
import httpretty import requests
Output: <Response [200]>
Is there also the opportunity to register a uri that cannot be reached (for example, connection timeout, connection failure, ...), so that no response is received at all (which does not match the established connection, which gives an HTTP error code such how is 404)?
I want to use this behavior in unit testing to ensure that my error handling works properly (which does different things if there is no connection and connection is established, bad HTTP code). As a workaround, I could try connecting to an invalid server, for example http://192.0.2.0 , which will time out anyway. However, I would prefer to run all my unit tests without using any real network connections.
source share