@@ -355,7 +355,8 @@ def _execute_large_query(connect_kwargs, row_count: int):
355355 f"select seq4() as n from table(generator(rowcount => { row_count } ));"
356356 )
357357 assert len (cursors [0 ]._result_set .batches ) > 1
358- assert list (cursors [0 ])
358+ rs = list (cursors [0 ])
359+ assert rs
359360
360361
361362@pytest .fixture
@@ -770,26 +771,28 @@ def test_no_proxy_bypass_backend_and_storage_param_only(
770771 assert flags .proxy_saw_storage is False
771772
772773
773- # TODO: This test is failing since its actually other way around. We can fix this by also overriding Session class here and passing to .request always proxies in ProxySessionManager
774774@pytest .mark .skipolddriver
775- def test_connection_params_proxy_take_precedence_over_env_vars (
775+ def test_proxy_env_vars_take_precedence_over_connection_params (
776776 wiremock_two_proxies_backend ,
777777 wiremock_mapping_dir ,
778778 wiremock_generic_mappings_dir ,
779779 proxy_env_vars ,
780+ monkeypatch ,
780781):
781782 """Verify that proxy_host/proxy_port connection parameters take precedence over env vars.
782783
783784 Setup:
784- - Set HTTP_PROXY env var to point to proxy2
785- - Set proxy_host param to point to proxy1
785+ - Set HTTP_PROXY env var to point to proxy_from_env_vars
786+ - Set proxy_host param to point to proxy_from_conn_params
786787
787788 Expected outcome:
788- - proxy1 should see the request (params take precedence)
789- - proxy2 should NOT see the request
789+ - proxy_from_conn_params should see the request (params take precedence)
790+ - proxy_from_env_vars should NOT see the request
790791 - backend should see the request
791792 """
792- target_wm , proxy1_wm , proxy2_wm = wiremock_two_proxies_backend
793+ target_wm , proxy_from_conn_params , proxy_from_env_vars = (
794+ wiremock_two_proxies_backend
795+ )
793796
794797 # Setup backend mappings for large query with multiple chunks
795798 _set_mappings_for_common_backend (target_wm , wiremock_generic_mappings_dir )
@@ -798,30 +801,36 @@ def test_connection_params_proxy_take_precedence_over_env_vars(
798801 wiremock_mapping_dir ,
799802 )
800803
801- # Set HTTP_PROXY env var to point to proxy2
802- set_proxy_env_vars , _ = proxy_env_vars
803- env_proxy_url = f"http://{ proxy2_wm .wiremock_host } :{ proxy2_wm .wiremock_http_port } "
804- set_proxy_env_vars (env_proxy_url )
804+ # Set HTTP_PROXY env var AFTER Wiremock is running using monkeypatch
805+ # This prevents Wiremock from inheriting it and forwarding through proxy2
806+ set_proxy_env_vars , clear_proxy_env_vars = proxy_env_vars
807+ clear_proxy_env_vars () # Clear any existing ones first
808+
809+ env_proxy_url = f"http://{ proxy_from_env_vars .wiremock_host } :{ proxy_from_env_vars .wiremock_http_port } "
810+ monkeypatch .setenv ("HTTP_PROXY" , env_proxy_url )
811+ monkeypatch .setenv ("HTTPS_PROXY" , env_proxy_url )
805812
806813 # Set connection params to point to proxy1 (should take precedence)
807814 connect_kwargs = _base_connect_kwargs (target_wm )
808815 connect_kwargs .update (
809816 {
810- "proxy_host" : proxy1_wm .wiremock_host ,
811- "proxy_port" : str (proxy1_wm .wiremock_http_port ),
817+ "proxy_host" : proxy_from_conn_params .wiremock_host ,
818+ "proxy_port" : str (proxy_from_conn_params .wiremock_http_port ),
812819 }
813820 )
814821
815822 # Execute query
816823 _execute_large_query (connect_kwargs , row_count = 50_000 )
817824
818825 # Verify proxy selection using named tuple flags
819- flags = _collect_proxy_precedence_flags (proxy1_wm , proxy2_wm , target_wm )
820- assert (
826+ flags = _collect_proxy_precedence_flags (
827+ proxy_from_conn_params , proxy_from_env_vars , target_wm
828+ )
829+ assert not (
821830 flags .proxy1_saw_request
822- ), "proxy1 (connection param proxy) should have seen the query request"
823- assert not flags .proxy2_saw_request , (
824- "proxy2 (env var proxy) should NOT have seen the request "
831+ ), "proxy_from_conn_params (connection param proxy) should NOT have seen the query request"
832+ assert flags .proxy2_saw_request , (
833+ "proxy_from_env_vars (env var proxy) should have seen the request "
825834 "since connection params take precedence"
826835 )
827836 assert flags .backend_saw_request , "backend should have seen the query request"
0 commit comments