@@ -107,8 +107,19 @@ def mock_ob_client():
107107
108108
109109def test_oceanbase_storage_initialization (mock_ob_client ):
110+ # Create a mock factory that returns a new mock IndexParams with iterator
111+ # each time
112+ def create_mock_index_params ():
113+ mock_index_param = MagicMock ()
114+ mock_index_params = MagicMock ()
115+ mock_index_params .__iter__ .return_value = iter ([mock_index_param ])
116+ return mock_index_params
117+
110118 with patch ('pyobvector.schema.VECTOR' ):
111- with patch ('pyobvector.client.index_param.IndexParams' ):
119+ with patch (
120+ 'pyobvector.client.index_param.IndexParams' ,
121+ side_effect = create_mock_index_params ,
122+ ):
112123 with patch ('pyobvector.client.index_param.IndexParam' ):
113124 # Test initialization with default parameters
114125 storage = OceanBaseStorage (
@@ -141,8 +152,19 @@ def test_oceanbase_storage_initialization(mock_ob_client):
141152
142153
143154def test_oceanbase_storage_operations (mock_ob_client ):
155+ # Create a mock factory that returns a new mock IndexParams with iterator
156+ # each time
157+ def create_mock_index_params ():
158+ mock_index_param = MagicMock ()
159+ mock_index_params = MagicMock ()
160+ mock_index_params .__iter__ .return_value = iter ([mock_index_param ])
161+ return mock_index_params
162+
144163 with patch ('pyobvector.schema.VECTOR' ):
145- with patch ('pyobvector.client.index_param.IndexParams' ):
164+ with patch (
165+ 'pyobvector.client.index_param.IndexParams' ,
166+ side_effect = create_mock_index_params ,
167+ ):
146168 with patch ('pyobvector.client.index_param.IndexParam' ):
147169 with patch ('sqlalchemy.func' ):
148170 # Setup mock for query results
@@ -187,9 +209,20 @@ def test_oceanbase_storage_operations(mock_ob_client):
187209
188210
189211def test_distance_to_similarity_conversion ():
212+ # Create a mock factory that returns a new mock IndexParams with iterator
213+ # each time
214+ def create_mock_index_params ():
215+ mock_index_param = MagicMock ()
216+ mock_index_params = MagicMock ()
217+ mock_index_params .__iter__ .return_value = iter ([mock_index_param ])
218+ return mock_index_params
219+
190220 with patch ('pyobvector.client.ObVecClient' ):
191221 with patch ('pyobvector.schema.VECTOR' ):
192- with patch ('pyobvector.client.index_param.IndexParams' ):
222+ with patch (
223+ 'pyobvector.client.index_param.IndexParams' ,
224+ side_effect = create_mock_index_params ,
225+ ):
193226 with patch ('pyobvector.client.index_param.IndexParam' ):
194227 # Test cosine distance conversion
195228 cosine_storage = OceanBaseStorage (
0 commit comments