@@ -75,8 +75,12 @@ async def test_qwen_oauth_static_routing_model_override_regression():
7575 mock_load_creds .return_value = True
7676
7777 # Mock the parent OpenAIConnector.chat_completions method to capture the call
78- with patch (
79- "src.connectors.openai.OpenAIConnector.chat_completions" ,
78+ # Use __bases__[0] to ensure we patch the exact base class object QwenOAuthConnector is using,
79+ # which handles cases where modules might be reloaded during tests.
80+ base_cls = QwenOAuthConnector .__bases__ [0 ]
81+ with patch .object (
82+ base_cls ,
83+ "chat_completions" ,
8084 new_callable = AsyncMock ,
8185 ) as mock_parent_chat :
8286
@@ -198,20 +202,24 @@ async def test_qwen_oauth_model_name_processing_with_static_routes():
198202 mock_load_creds .return_value = True
199203
200204 # Mock the parent OpenAIConnector.chat_completions method
201- with patch (
202- "src.connectors.openai.OpenAIConnector.chat_completions" ,
205+ # Use __bases__[0] to ensure we patch the exact base class object QwenOAuthConnector is using,
206+ # which handles cases where modules might be reloaded during tests.
207+ base_cls = QwenOAuthConnector .__bases__ [0 ]
208+ with patch .object (
209+ base_cls ,
210+ "chat_completions" ,
203211 new_callable = AsyncMock ,
204212 ) as mock_parent_chat :
205-
206- from src .core .domain .responses import ResponseEnvelope
207-
208- mock_response_envelope = ResponseEnvelope (
209- content = "Test response" , usage = MagicMock (total_tokens = 10 )
210- )
211- mock_parent_chat .return_value = mock_response_envelope
212-
213- # Test various static routing scenarios
214- test_cases = [
213+
214+ from src .core .domain .responses import ResponseEnvelope
215+
216+ mock_response_envelope = ResponseEnvelope (
217+ content = "Test response" , usage = MagicMock (total_tokens = 10 )
218+ )
219+ mock_parent_chat .return_value = mock_response_envelope
220+
221+ # Test various static routing scenarios
222+ test_cases = [
215223 {
216224 "original_model" : "gemini-cli-oauth-personal:models/gemini-2.5-pro" ,
217225 "static_override" : "qwen-oauth:qwen3-coder-plus" ,
@@ -325,20 +333,24 @@ async def test_qwen_oauth_prevents_original_model_leakage():
325333 mock_load_creds .return_value = True
326334
327335 # Mock the parent OpenAIConnector.chat_completions method
328- with patch (
329- "src.connectors.openai.OpenAIConnector.chat_completions" ,
336+ # Use __bases__[0] to ensure we patch the exact base class object QwenOAuthConnector is using,
337+ # which handles cases where modules might be reloaded during tests.
338+ base_cls = QwenOAuthConnector .__bases__ [0 ]
339+ with patch .object (
340+ base_cls ,
341+ "chat_completions" ,
330342 new_callable = AsyncMock ,
331343 ) as mock_parent_chat :
332-
333- from src .core .domain .responses import ResponseEnvelope
334-
335- mock_response_envelope = ResponseEnvelope (
336- content = "Test response" , usage = MagicMock (total_tokens = 10 )
337- )
338- mock_parent_chat .return_value = mock_response_envelope
339-
340- # Create a request with a completely different original model
341- original_model = (
344+
345+ from src .core .domain .responses import ResponseEnvelope
346+
347+ mock_response_envelope = ResponseEnvelope (
348+ content = "Test response" , usage = MagicMock (total_tokens = 10 )
349+ )
350+ mock_parent_chat .return_value = mock_response_envelope
351+
352+ # Create a request with a completely different original model
353+ original_model = (
342354 "some-other-backend:some-completely-different-model-name"
343355 )
344356 static_override_model = "qwen3-coder-plus"
0 commit comments