cdent / wsgi-intercept

Intercept socket connection to wsgi applications for testing
MIT License
42 stars 21 forks source link

A number of tests are failing #77

Open musicinmybrain opened 1 month ago

musicinmybrain commented 1 month ago

Simply checking out the repository and running tox with the py312 environment results in a number of test failures. (Some of these take a long time to fail!)

$ gh repo clone cdent/wsgi-intercept
$ cd wsgi-intercept
$ tox -e py312
============================================================================================= test session starts ==============================================================================================
platform linux -- Python 3.12.4, pytest-8.3.2, pluggy-1.5.0
cachedir: .tox/py312/.pytest_cache
rootdir: /home/ben/src/forks/wsgi-intercept
collected 81 items                                                                                                                                                                                             

wsgi_intercept/tests/test_http_client.py .......                                                                                                                                                         [  8%]
wsgi_intercept/tests/test_httplib2.py ...F....                                                                                                                                                           [ 18%]
wsgi_intercept/tests/test_interceptor.py ....F....F..........                                                                                                                                            [ 43%]
wsgi_intercept/tests/test_module_interceptor.py ..                                                                                                                                                       [ 45%]
wsgi_intercept/tests/test_requests.py ...F.F..F..F                                                                                                                                                       [ 60%]
wsgi_intercept/tests/test_response_headers.py ..                                                                                                                                                         [ 62%]
wsgi_intercept/tests/test_urllib.py .........                                                                                                                                                            [ 74%]
wsgi_intercept/tests/test_urllib3.py ...F.......                                                                                                                                                         [ 87%]
wsgi_intercept/tests/test_wsgi_compliance.py .........                                                                                                                                                   [ 98%]
wsgi_intercept/tests/test_wsgiref.py .                                                                                                                                                                   [100%]

=================================================================================================== FAILURES ===================================================================================================
______________________________________________________________________________________________ test_bogus_domain _______________________________________________________________________________________________
wsgi_intercept/tests/test_httplib2.py:45: in test_bogus_domain
    with pytest.raises(gaierror):
E   Failed: DID NOT RAISE <class 'socket.gaierror'>
____________________________________________________________________________________________ test_httpclient_in_out ____________________________________________________________________________________________
wsgi_intercept/tests/test_interceptor.py:104: in test_httpclient_in_out
    client.request('GET', '/')
/usr/lib64/python3.12/http/client.py:1336: in request
    self._send_request(method, url, body, headers, encode_chunked)
/usr/lib64/python3.12/http/client.py:1382: in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
/usr/lib64/python3.12/http/client.py:1331: in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
/usr/lib64/python3.12/http/client.py:1091: in _send_output
    self.send(msg)
/usr/lib64/python3.12/http/client.py:1035: in send
    self.connect()
/usr/lib64/python3.12/http/client.py:1001: in connect
    self.sock = self._create_connection( 
/usr/lib64/python3.12/socket.py:853: in create_connection
    raise exceptions[0]
/usr/lib64/python3.12/socket.py:838: in create_connection
    sock.connect(sa)
E   TimeoutError: [Errno 110] Connection timed out
_____________________________________________________________________________________________ test_httplib2_in_out _____________________________________________________________________________________________
wsgi_intercept/tests/test_interceptor.py:163: in test_httplib2_in_out
    http.request(url)
.tox/py312/lib/python3.12/site-packages/httplib2/__init__.py:1724: in request
    (response, content) = self._request( 
.tox/py312/lib/python3.12/site-packages/httplib2/__init__.py:1444: in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
.tox/py312/lib/python3.12/site-packages/httplib2/__init__.py:1366: in _conn_request
    conn.connect()
wsgi_intercept/__init__.py:572: in connect
    HTTPConnection.connect(self)
/usr/lib64/python3.12/http/client.py:1001: in connect
    self.sock = self._create_connection( 
/usr/lib64/python3.12/socket.py:853: in create_connection
    raise exceptions[0]
/usr/lib64/python3.12/socket.py:838: in create_connection
    sock.connect(sa)
E   TimeoutError: [Errno 110] Connection timed out
______________________________________________________________________________________________ test_bogus_domain _______________________________________________________________________________________________
wsgi_intercept/tests/test_requests.py:39: in test_bogus_domain
    with pytest.raises(ConnectionError): 
E   Failed: DID NOT RAISE <class 'requests.exceptions.ConnectionError'>
__________________________________________________________________________________________________ test_https __________________________________________________________________________________________________
wsgi_intercept/tests/test_requests.py:57: in test_https
    resp = requests.get('https://some_hopefully_nonexistant_domain:443/')
.tox/py312/lib/python3.12/site-packages/requests/api.py:73: in get
    return request("get", url, params=params, **kwargs)
.tox/py312/lib/python3.12/site-packages/requests/api.py:59: in request
    return session.request(method=method, url=url, **kwargs)
.tox/py312/lib/python3.12/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
.tox/py312/lib/python3.12/site-packages/requests/sessions.py:703: in send
    r = adapter.send(request, **kwargs)  
.tox/py312/lib/python3.12/site-packages/requests/adapters.py:667: in send
    resp = conn.urlopen(
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:704: in urlopen
    conn = self._get_conn(timeout=pool_timeout)
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:299: in _get_conn
    return conn or self._new_conn()
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:1039: in _new_conn
    conn = self.ConnectionCls(
wsgi_intercept/_urllib3.py:36: in __init__
    WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
E   TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'ssl_context'
___________________________________________________________________________________________ test_https_default_port ____________________________________________________________________________________________
wsgi_intercept/tests/test_requests.py:80: in test_https_default_port
    resp = requests.get('https://some_hopefully_nonexistant_domain/')
.tox/py312/lib/python3.12/site-packages/requests/api.py:73: in get
    return request("get", url, params=params, **kwargs)
.tox/py312/lib/python3.12/site-packages/requests/api.py:59: in request
    return session.request(method=method, url=url, **kwargs)
.tox/py312/lib/python3.12/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
.tox/py312/lib/python3.12/site-packages/requests/sessions.py:703: in send
    r = adapter.send(request, **kwargs)  
.tox/py312/lib/python3.12/site-packages/requests/adapters.py:667: in send
    resp = conn.urlopen(
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:704: in urlopen
    conn = self._get_conn(timeout=pool_timeout)
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:299: in _get_conn
    return conn or self._new_conn()
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:1039: in _new_conn
    conn = self.ConnectionCls(
wsgi_intercept/_urllib3.py:36: in __init__
    WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
E   TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'ssl_context'
__________________________________________________________________________________________ test_https_not_intercepted __________________________________________________________________________________________
wsgi_intercept/tests/test_requests.py:103: in test_https_not_intercepted
    resp = requests.get("https://google.com")
.tox/py312/lib/python3.12/site-packages/requests/api.py:73: in get
    return request("get", url, params=params, **kwargs)
.tox/py312/lib/python3.12/site-packages/requests/api.py:59: in request
    return session.request(method=method, url=url, **kwargs)
.tox/py312/lib/python3.12/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
.tox/py312/lib/python3.12/site-packages/requests/sessions.py:703: in send
    r = adapter.send(request, **kwargs)  
.tox/py312/lib/python3.12/site-packages/requests/adapters.py:667: in send
    resp = conn.urlopen(
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:704: in urlopen
    conn = self._get_conn(timeout=pool_timeout)
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:299: in _get_conn
    return conn or self._new_conn()
.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py:1039: in _new_conn
    conn = self.ConnectionCls(
wsgi_intercept/_urllib3.py:36: in __init__
    WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
E   TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'ssl_context'
______________________________________________________________________________________________ test_bogus_domain _______________________________________________________________________________________________
wsgi_intercept/tests/test_urllib3.py:41: in test_bogus_domain
    with pytest.raises(urllib3.exceptions.ProtocolError):
E   Failed: DID NOT RAISE <class 'urllib3.exceptions.ProtocolError'>
=========================================================================================== short test summary info ============================================================================================
FAILED wsgi_intercept/tests/test_httplib2.py::test_bogus_domain - Failed: DID NOT RAISE <class 'socket.gaierror'>
FAILED wsgi_intercept/tests/test_interceptor.py::test_httpclient_in_out - TimeoutError: [Errno 110] Connection timed out
FAILED wsgi_intercept/tests/test_interceptor.py::test_httplib2_in_out - TimeoutError: [Errno 110] Connection timed out
FAILED wsgi_intercept/tests/test_requests.py::test_bogus_domain - Failed: DID NOT RAISE <class 'requests.exceptions.ConnectionError'>
FAILED wsgi_intercept/tests/test_requests.py::test_https - TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'ssl_context'
FAILED wsgi_intercept/tests/test_requests.py::test_https_default_port - TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'ssl_context'
FAILED wsgi_intercept/tests/test_requests.py::test_https_not_intercepted - TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'ssl_context'
FAILED wsgi_intercept/tests/test_urllib3.py::test_bogus_domain - Failed: DID NOT RAISE <class 'urllib3.exceptions.ProtocolError'>
================================================================================== 8 failed, 73 passed in 2166.38s (0:36:06) ===================================================================================
cdent commented 1 month ago

when I tox -r -e py312 I get 3 failures but they are all based on TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'ssl_context'. This is something new with 3.12 that needs to be addressed.

The pattern of your other failures suggests some kind of network issue, what happens if you run WSGI_INTERCEPT_SKIP_NETWORK=True tox -e py312

Those tests which are skipped tend to rely on resolving google.com, so if you've got that blocked for some reason that may be a factor.

If you could let me know if that's perhaps a factor, that would be helpful.

In the meantime I'll see what can be done about the ssl_context stuff.

cdent commented 1 month ago

Its requests. Needs to be pinned. It's changed it's interface or the things its vendor. there was a new release recently.