gabrielfalcao / HTTPretty

Intercept HTTP requests at the Python socket level. Fakes the whole socket module
https://httpretty.readthedocs.org
MIT License
2.11k stars 276 forks source link

httpretty silently fails with Python 3.12 #474

Open kfrydel opened 1 year ago

kfrydel commented 1 year ago

We are switching our project to Python 3.12. We use pytest and httpretty in order to mock some requests. From Python 3.12 datetime.utcnow is deprecated: https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow When running tests using pytest, warnings raise an exception and since datetime.utcnow is used by httpretty in a thread: https://github.com/gabrielfalcao/HTTPretty/blob/main/httpretty/core.py#L1077 the warning is not visible anywhere. httpretty does not fill the file with HTTP content and tests fail with something like this: ConnectionError: Error requesting 'http://localhost:9000/path': ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')). It fails because http client gets an empty string from the file when trying to read the first line of HTTP response: https://github.com/python/cpython/blob/3.12/Lib/http/client.py#L285

It can be workarounded by adding an ignore to pytest.ini file.

jobarjo commented 1 month ago

@kfrydel - many thanks for this! Took me quite some time before finding this (did not appear on my G searches :D