abhinavsingh / proxy.py

💫 Ngrok FRP Alternative • ⚡ Fast • 🪶 Lightweight • 0️⃣ Dependency • 🔌 Pluggable • 😈 TLS interception • 🔒 DNS-over-HTTPS • 🔥 Poor Man's VPN • ⏪ Reverse & ⏩ Forward • 👮🏿 "Proxy Server" framework • 🌐 "Web Server" framework • ➵ ➶ ➷ ➠ "PubSub" framework • 👷 "Work" acceptor & executor framework
https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/
BSD 3-Clause "New" or "Revised" License
2.91k stars 568 forks source link

Tests are broken with pytest-asyncio-0.23* #1427

Open mgorny opened 1 week ago

mgorny commented 1 week ago

Describe the bug When running the test suite against pytest-asyncio == 0.23.7, I'm getting lots of errors:

ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_fails_without_cred - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_fails_without_cred - ExceptionGroup: errors while tearing down fixture "event_loop" of <Coroutine test_proxy_auth_fails_without_cred> (2 sub-exceptions)
ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_fails_with_invalid_cred - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket object, fd=-1, family=1, type=1, proto=0>
ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_fails_with_invalid_cred - TypeError: TestHttpProxyAuthFailed._setUp.<locals>.<lambda>() takes 0 positional arguments but 4 were given
ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_works_with_valid_cred - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_works_with_valid_cred - TypeError: TestHttpProxyAuthFailed._setUp.<locals>.<lambda>() takes 0 positional arguments but 4 were given
ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_works_with_mixed_case_basic_string - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/exceptions/test_http_proxy_auth_failed.py::TestHttpProxyAuthFailed::test_proxy_auth_works_with_mixed_case_basic_string - TypeError: TestHttpProxyAuthFailed._setUp.<locals>.<lambda>() takes 0 positional arguments but 4 were given
ERROR tests/http/proxy/test_http_proxy.py::TestHttpProxyPlugin::test_proxy_plugin_on_and_before_upstream_connection - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/proxy/test_http_proxy.py::TestHttpProxyPlugin::test_proxy_plugin_on_and_before_upstream_connection - TypeError: TestHttpProxyPlugin._setUp.<locals>.<lambda>() takes 0 positional arguments but 4 were given
ERROR tests/http/proxy/test_http_proxy.py::TestHttpProxyPlugin::test_proxy_plugin_before_upstream_connection_can_teardown - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/proxy/test_http_proxy.py::TestHttpProxyPlugin::test_proxy_plugin_before_upstream_connection_can_teardown - TypeError: TestHttpProxyPlugin._setUp.<locals>.<lambda>() takes 0 positional arguments but 4 were given
ERROR tests/http/proxy/test_http_proxy_tls_interception.py::TestHttpProxyTlsInterception::test_e2e - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_connection_failed - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_connection_failed - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_authentication_failed - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_authentication_failed - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_bails_out_for_unknown_schemes - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_bails_out_for_unknown_schemes - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_bails_out_for_sip_request_lines - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandlerWithoutServerMock::test_proxy_bails_out_for_sip_request_lines - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_http_get - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_http_get - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_http_tunnel - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_http_tunnel - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_authenticated_proxy_http_get - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_authenticated_proxy_http_get - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_authenticated_proxy_http_tunnel - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/test_protocol_handler.py::TestHttpProtocolHandler::test_authenticated_proxy_http_tunnel - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/web/test_web_server.py::TestWebServerPluginWithPacFilePlugin::test_pac_file_served_from_disk[/tmp/proxy.py/helper/proxy.pac] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/web/test_web_server.py::TestWebServerPluginWithPacFilePlugin::test_pac_file_served_from_disk[/tmp/proxy.py/helper/proxy.pac] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/web/test_web_server.py::TestWebServerPluginWithPacFilePlugin::test_pac_file_served_from_disk[function FindProxyForURL(url, host) { return "PROXY localhost:8899; DIRECT"; }] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/web/test_web_server.py::TestWebServerPluginWithPacFilePlugin::test_pac_file_served_from_disk[function FindProxyForURL(url, host) { return "PROXY localhost:8899; DIRECT"; }] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/web/test_web_server.py::TestStaticWebServerPlugin::test_static_web_server_serves - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/web/test_web_server.py::TestStaticWebServerPlugin::test_static_web_server_serves - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/web/test_web_server.py::TestStaticWebServerPlugin::test_static_web_server_serves_404 - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/web/test_web_server.py::TestStaticWebServerPlugin::test_static_web_server_serves_404 - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/http/web/test_web_server.py::TestWebServerPlugin::test_default_web_server_returns_404 - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/http/web/test_web_server.py::TestWebServerPlugin::test_default_web_server_returns_404 - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_modify_post_data_plugin[test_modify_post_data_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_modify_post_data_plugin[test_modify_post_data_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_proposed_rest_api_plugin[test_proposed_rest_api_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_proposed_rest_api_plugin[test_proposed_rest_api_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_redirect_to_custom_server_plugin[test_redirect_to_custom_server_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_redirect_to_custom_server_plugin[test_redirect_to_custom_server_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_redirect_to_custom_server_plugin_skips_https[test_redirect_to_custom_server_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_redirect_to_custom_server_plugin_skips_https[test_redirect_to_custom_server_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_filter_by_upstream_host_plugin[test_filter_by_upstream_host_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_filter_by_upstream_host_plugin[test_filter_by_upstream_host_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_man_in_the_middle_plugin[test_man_in_the_middle_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_man_in_the_middle_plugin[test_man_in_the_middle_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_filter_by_url_regex_plugin[test_filter_by_url_regex_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_filter_by_url_regex_plugin[test_filter_by_url_regex_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_shortlink_plugin[test_shortlink_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_shortlink_plugin[test_shortlink_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_shortlink_plugin_unknown[test_shortlink_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_shortlink_plugin_unknown[test_shortlink_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_shortlink_plugin_external[test_shortlink_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_shortlink_plugin_external[test_shortlink_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_auth_plugin[test_auth_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_auth_plugin[test_auth_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_auth_plugin_bypass[test_auth_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins.py::TestHttpProxyPluginExamples::test_auth_plugin_bypass[test_auth_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins_with_tls_interception.py::TestHttpProxyPluginExamplesWithTlsInterception::test_modify_post_data_plugin[test_modify_post_data_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins_with_tls_interception.py::TestHttpProxyPluginExamplesWithTlsInterception::test_modify_post_data_plugin[test_modify_post_data_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
ERROR tests/plugin/test_http_proxy_plugins_with_tls_interception.py::TestHttpProxyPluginExamplesWithTlsInterception::test_man_in_the_middle_plugin[test_man_in_the_middle_plugin] - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
ERROR tests/plugin/test_http_proxy_plugins_with_tls_interception.py::TestHttpProxyPluginExamplesWithTlsInterception::test_man_in_the_middle_plugin[test_man_in_the_middle_plugin] - ValueError: not enough values to unpack (expected 2, got 0)
FAILED tests/http/proxy/test_http_proxy_tls_interception.py::TestHttpProxyTlsInterception::test_e2e - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket object, fd=-1, family=1, type=1, proto=0>
FAILED tests/test_main.py::TestMain::test_enable_events - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=-1, family=1, type=1, proto=0>

Test log (760 KiB): test.txt

To Reproduce

tox -e py311
. .tox/py311/bin/activate
pip install -U pytest-asyncio
pytest --ignore tests/integration # (because of #1426)

Expected behavior Tests passing.

Version information

Additional context Some tracebacks (from the log):

Exception ignore
d in: <function BaseEventLoop.__del__ at 0x7fa65ac505e0>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/base_events.py", line 695, in __del__
    self.close()
  File "/usr/lib/python3.11/asyncio/unix_events.py", line 68, in close
    super().close()
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 91, in close
    self._close_self_pipe()
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 98, in _close_self_pipe
    self._remove_reader(self._ssock.fileno())
                        ^^^^^^^^^^^
AttributeError: '_UnixSelectorEventLoop' object has no attribute '_ssock'
self = <_UnixSelectorEventLoop running=False closed=False debug=False>, fd = 125
callback = <bound method BaseSelectorEventLoop._read_from_self of <_UnixSelectorEventLoop running=False closed=False debug=False>>
args = (), handle = <Handle BaseSelectorEventLoop._read_from_self()>
key = <MagicMock name='DefaultSelector().get_key()' id='140352427893520'>
mask = <MagicMock name='DefaultSelector().get_key().events' id='140352423194960'>

    def _add_reader(self, fd, callback, *args):
        self._check_closed()
        handle = events.Handle(callback, args, self, None)
        try:
            key = self._selector.get_key(fd)
        except KeyError:
            self._selector.register(fd, selectors.EVENT_READ,
                                    (handle, None))
        else:
>           mask, (reader, writer) = key.events, key.data
E           ValueError: not enough values to unpack (expected 2, got 0)

args       = ()
callback   = <bound method BaseSelectorEventLoop._read_from_self of <_UnixSelectorEventLoop running=False closed=False debug=False>>
fd         = 125
handle     = <Handle BaseSelectorEventLoop._read_from_self()>
key        = <MagicMock name='DefaultSelector().get_key()' id='140352427893520'>
mask       = <MagicMock name='DefaultSelector().get_key().events' id='140352423194960'>
self       = <_UnixSelectorEventLoop running=False closed=False debug=False>

/usr/lib/python3.11/asyncio/selector_events.py:274: ValueError

Screenshots If applicable, add screenshots to help explain your problem.