1313)
1414
1515
16- def _configure_mock_workspace_client (mock_client ):
17- """Configure a mock workspace client with proper authentication return values."""
18- # Ensure config.authenticate() returns a proper Bearer token string
19- mock_client .config .authenticate .return_value = {"Authorization" : "Bearer mock-token" }
20- mock_client .config .host = "https://test.databricks.com"
21- return mock_client
22-
23-
2416@pytest .fixture (autouse = True )
2517def mock_databricks_oauth_provider ():
2618 """Auto-mock DatabricksOAuthClientProvider for all tests to avoid OAuth validation errors."""
@@ -64,7 +56,6 @@ def __init__(self, role, content):
6456
6557@patch ("databricks.sdk.WorkspaceClient" )
6658def test_query_genie_as_agent (MockWorkspaceClient ):
67- _configure_mock_workspace_client (MockWorkspaceClient )
6859 mock_space = GenieSpace (
6960 space_id = "space-id" ,
7061 title = "Sales Space" ,
@@ -83,8 +74,8 @@ def test_query_genie_as_agent(MockWorkspaceClient):
8374 input_data = {"messages" : [{"role" : "user" , "content" : "What is the weather?" }]}
8475 genie = Genie ("space-id" , MockWorkspaceClient )
8576
86- # Mock the ask_question method to return our mock response
87- with patch . object ( genie , " ask_question" , return_value = mock_genie_response ):
77+ # Mock the ask_question method at the module level to avoid mlflow tracing issues
78+ with patch ( "databricks_ai_bridge.genie.Genie. ask_question" , return_value = mock_genie_response ):
8879 # Test with include_context=False (default)
8980 result = _query_genie_as_agent (input_data , genie , "Genie" )
9081 expected_message = {
@@ -115,7 +106,6 @@ def test_create_genie_agent(MockRunnableLambda, MockWorkspaceClient):
115106 description = "description" ,
116107 )
117108 mock_client = MockWorkspaceClient .return_value
118- _configure_mock_workspace_client (mock_client )
119109 mock_client .genie .get_space .return_value = mock_space
120110
121111 agent = GenieAgent ("space-id" , "Genie" , client = mock_client )
@@ -134,7 +124,6 @@ def test_create_genie_agent_with_description(MockRunnableLambda, MockWorkspaceCl
134124 description = None ,
135125 )
136126 mock_client = MockWorkspaceClient .return_value
137- _configure_mock_workspace_client (mock_client )
138127 mock_client .genie .get_space .return_value = mock_space
139128
140129 agent = GenieAgent ("space-id" , "Genie" , "this is a description" , client = mock_client )
@@ -146,7 +135,6 @@ def test_create_genie_agent_with_description(MockRunnableLambda, MockWorkspaceCl
146135
147136@patch ("databricks.sdk.WorkspaceClient" )
148137def test_query_genie_with_client (mock_workspace_client ):
149- _configure_mock_workspace_client (mock_workspace_client )
150138 mock_workspace_client .genie .get_space .return_value = GenieSpace (
151139 space_id = "space-id" ,
152140 title = "Sales Space" ,
@@ -164,8 +152,8 @@ def test_query_genie_with_client(mock_workspace_client):
164152 input_data = {"messages" : [{"role" : "user" , "content" : "What is the weather?" }]}
165153 genie = Genie ("space-id" , mock_workspace_client )
166154
167- # Mock the ask_question method to return our mock response
168- with patch . object ( genie , " ask_question" , return_value = mock_genie_response ):
155+ # Mock the ask_question method at the module level to avoid mlflow tracing issues
156+ with patch ( "databricks_ai_bridge.genie.Genie. ask_question" , return_value = mock_genie_response ):
169157 result = _query_genie_as_agent (input_data , genie , "Genie" )
170158 expected_message = {
171159 "messages" : [AIMessage (content = "It is sunny." , name = "query_result" )],
@@ -183,7 +171,6 @@ def test_create_genie_agent_with_include_context(MockWorkspaceClient):
183171 description = "description" ,
184172 )
185173 mock_client = MockWorkspaceClient .return_value
186- _configure_mock_workspace_client (mock_client )
187174 mock_client .genie .get_space .return_value = mock_space
188175
189176 # Create a proper GenieResponse instance
@@ -226,7 +213,6 @@ def test_create_genie_agent_no_space_id():
226213@patch ("databricks.sdk.WorkspaceClient" )
227214def test_message_processor_functionality (MockWorkspaceClient ):
228215 """Test message_processor parameter in both _query_genie_as_agent and GenieAgent"""
229- _configure_mock_workspace_client (MockWorkspaceClient )
230216 mock_space = GenieSpace (space_id = "space-id" , title = "Sales Space" , description = "description" )
231217 MockWorkspaceClient .genie .get_space .return_value = mock_space
232218
@@ -314,7 +300,6 @@ def last_message_processor(messages):
314300@patch ("databricks.sdk.WorkspaceClient" )
315301def test_conversation_continuity (MockWorkspaceClient ):
316302 """Test that conversation_id is passed through correctly for conversation continuity"""
317- _configure_mock_workspace_client (MockWorkspaceClient )
318303 mock_space = GenieSpace (
319304 space_id = "space-id" ,
320305 title = "Sales Space" ,
@@ -373,7 +358,6 @@ def test_dataframe_return(MockWorkspaceClient):
373358 """Test that DataFrames are returned correctly with markdown conversion"""
374359 import pandas as pd
375360
376- _configure_mock_workspace_client (MockWorkspaceClient )
377361 mock_space = GenieSpace (
378362 space_id = "space-id" ,
379363 title = "Sales Space" ,
@@ -414,7 +398,6 @@ def test_dataframe_return(MockWorkspaceClient):
414398@patch ("databricks.sdk.WorkspaceClient" )
415399def test_string_return_no_dataframe_field (MockWorkspaceClient ):
416400 """Test that string results don't include dataframe field"""
417- _configure_mock_workspace_client (MockWorkspaceClient )
418401 mock_space = GenieSpace (
419402 space_id = "space-id" ,
420403 title = "Sales Space" ,
0 commit comments