1515@pytest .fixture
1616def mock_async_openai ():
1717 """Fixture to mock AsyncOpenAI client."""
18- with patch ("device_use.backends.openai_compat.AsyncOpenAI" ) as MockAsyncOpenAI :
19- mock_client = MockAsyncOpenAI .return_value
20- yield MockAsyncOpenAI , mock_client
18+ with patch ("device_use.backends.openai_compat.AsyncOpenAI" ) as mock_openai_cls :
19+ mock_client = mock_openai_cls .return_value
20+ yield mock_openai_cls , mock_client
2121
2222
2323class TestSupportsComputerUse :
@@ -55,8 +55,8 @@ class TestOpenAICompatBackendInitialization:
5555 ],
5656 )
5757 def test_initialization (self , mock_async_openai , model , expected_native_cu ):
58- MockAsyncOpenAI_class , mock_async_openai_instance = mock_async_openai
59- MockAsyncOpenAI_class .reset_mock ()
58+ mock_openai_cls , mock_async_openai_instance = mock_async_openai
59+ mock_openai_cls .reset_mock ()
6060 backend = OpenAICompatBackend (model = model , api_key = "test_key" , base_url = "http://test.url" )
6161
6262 assert backend ._model == model
@@ -66,19 +66,17 @@ def test_initialization(self, mock_async_openai, model, expected_native_cu):
6666 assert backend .system_prompt == ""
6767 assert backend ._previous_response_id is None
6868
69- MockAsyncOpenAI_class .assert_called_once_with (
70- api_key = "test_key" , base_url = "http://test.url"
71- )
69+ mock_openai_cls .assert_called_once_with (api_key = "test_key" , base_url = "http://test.url" )
7270
7371 def test_default_values (self , mock_async_openai ):
74- MockAsyncOpenAI_class , mock_async_openai_instance = mock_async_openai
72+ mock_openai_cls , mock_async_openai_instance = mock_async_openai
7573 backend = OpenAICompatBackend (api_key = "test_key" ) # Add api_key here
7674 assert backend ._model == "gpt-5.4"
7775 assert backend ._max_tokens == 4096
7876 assert backend ._native_cu is True # gpt-5.4 is default
7977
8078 def test_supports_grounding_property (self , mock_async_openai ):
81- MockAsyncOpenAI_class , mock_async_openai_instance = mock_async_openai
79+ mock_openai_cls , mock_async_openai_instance = mock_async_openai
8280 cu_backend = OpenAICompatBackend (model = "gpt-5.4" , api_key = "test_key" )
8381 assert cu_backend .supports_grounding is True
8482
@@ -87,7 +85,7 @@ def test_supports_grounding_property(self, mock_async_openai):
8785
8886 @pytest .fixture (autouse = True )
8987 def setup (self , mock_async_openai ):
90- MockAsyncOpenAI_class , self .mock_client = mock_async_openai
88+ mock_openai_cls , self .mock_client = mock_async_openai
9189 self .cu_backend = OpenAICompatBackend (model = "gpt-5.4" , api_key = "test_key" )
9290 self .mock_responses_create = AsyncMock ()
9391 self .mock_client .responses .create = self .mock_responses_create
@@ -272,7 +270,7 @@ class TestMapCUAction:
272270
273271 @pytest .fixture (autouse = True )
274272 def setup (self , mock_async_openai ):
275- MockAsyncOpenAI_class , mock_client = (
273+ mock_openai_cls , mock_client = (
276274 mock_async_openai # unpack here, not used directly in this fixture, but good practice
277275 )
278276 self .backend = OpenAICompatBackend (model = "gpt-5.4" , api_key = "test_key" )
@@ -633,7 +631,7 @@ class TestPlanObserveLocate:
633631
634632 @pytest .fixture (autouse = True )
635633 def setup (self , mock_async_openai ):
636- MockAsyncOpenAI_class , self .mock_client = mock_async_openai
634+ mock_openai_cls , self .mock_client = mock_async_openai
637635 self .cu_backend = OpenAICompatBackend (model = "gpt-5.4" , api_key = "test_key" )
638636 self .legacy_backend = OpenAICompatBackend (model = "gpt-4o" , api_key = "test_key" )
639637 self .mock_responses_create = AsyncMock ()
@@ -813,9 +811,10 @@ async def test_plan_native_remaining_actions(self):
813811
814812 async def test_plan_legacy (self ):
815813 mock_choice = MagicMock ()
816- mock_choice .message .content = """
817- {"action": {"action_type": "type", "text": "hello"}, "reasoning": "type text", "done": false, "confidence": 0.8}
818- """
814+ mock_choice .message .content = (
815+ '{"action": {"action_type": "type", "text": "hello"},'
816+ ' "reasoning": "type text", "done": false, "confidence": 0.8}'
817+ )
819818 self .mock_chat_completions_create .return_value = MagicMock (choices = [mock_choice ])
820819
821820 result = await self .legacy_backend .plan (self .screenshot_bytes , "task" , history = [])
@@ -865,7 +864,7 @@ class TestLegacyChatCompletions:
865864
866865 @pytest .fixture (autouse = True )
867866 def setup (self , mock_async_openai ):
868- MockAsyncOpenAI_class , self .mock_client = mock_async_openai
867+ mock_openai_cls , self .mock_client = mock_async_openai
869868 self .legacy_backend = OpenAICompatBackend (model = "gpt-4o" , api_key = "test_key" )
870869 self .mock_chat_completions_create = AsyncMock ()
871870 self .mock_client .chat .completions .create = self .mock_chat_completions_create
0 commit comments