Skip to content

Commit 9fd0fe0

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: flaky tests in feature store relates cases due to class instantiation
PiperOrigin-RevId: 910747896
1 parent 762d20c commit 9fd0fe0

12 files changed

Lines changed: 147 additions & 135 deletions

tests/unit/agentplatform/test_feature.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_init_with_feature_id_and_no_fg_id_raises_error(get_feature_mock):
118118
+ " feature_group_id."
119119
),
120120
):
121-
Feature(_TEST_FG1_F1_ID)
121+
Feature(name=_TEST_FG1_F1_ID)
122122

123123

124124
def test_init_with_feature_path_and_fg_id_raises_error(get_feature_mock):
@@ -130,13 +130,13 @@ def test_init_with_feature_path_and_fg_id_raises_error(get_feature_mock):
130130
"Since feature 'projects/test-project/locations/us-central1/featureGroups/my_fg1/features/my_fg1_f1' is provided as a path, feature_group_id should not be specified."
131131
),
132132
):
133-
Feature(_TEST_FG1_F1_PATH, feature_group_id=_TEST_FG1_ID)
133+
Feature(name=_TEST_FG1_F1_PATH, feature_group_id=_TEST_FG1_ID)
134134

135135

136136
def test_init_with_feature_id(get_feature_mock):
137137
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
138138

139-
feature = Feature(_TEST_FG1_F1_ID, feature_group_id=_TEST_FG1_ID)
139+
feature = Feature(name=_TEST_FG1_F1_ID, feature_group_id=_TEST_FG1_ID)
140140

141141
get_feature_mock.assert_called_once_with(
142142
name=_TEST_FG1_F1_PATH,
@@ -160,7 +160,7 @@ def test_init_with_feature_id_for_explicit_version_column(
160160
):
161161
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
162162

163-
feature = Feature(_TEST_FG1_F2_ID, feature_group_id=_TEST_FG1_ID)
163+
feature = Feature(name=_TEST_FG1_F2_ID, feature_group_id=_TEST_FG1_ID)
164164

165165
get_feature_with_version_column_mock.assert_called_once_with(
166166
name=_TEST_FG1_F2_PATH,
@@ -183,7 +183,7 @@ def test_init_with_feature_id_for_explicit_version_column(
183183
def test_init_with_feature_path(get_feature_mock):
184184
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
185185

186-
feature = Feature(_TEST_FG1_F1_PATH)
186+
feature = Feature(name=_TEST_FG1_F1_PATH)
187187

188188
get_feature_mock.assert_called_once_with(
189189
name=_TEST_FG1_F1_PATH,
@@ -207,7 +207,7 @@ def test_init_with_feature_path_for_explicit_version_column(
207207
):
208208
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
209209

210-
feature = Feature(_TEST_FG1_F2_PATH)
210+
feature = Feature(name=_TEST_FG1_F2_PATH)
211211

212212
get_feature_with_version_column_mock.assert_called_once_with(
213213
name=_TEST_FG1_F2_PATH,
@@ -260,7 +260,7 @@ def test_delete_feature(
260260
):
261261
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
262262

263-
feature = FeatureGroup(_TEST_FG1_ID).get_feature(_TEST_FG1_F1_ID)
263+
feature = FeatureGroup(name=_TEST_FG1_ID).get_feature(_TEST_FG1_F1_ID)
264264
feature.delete(sync=sync)
265265

266266
if not sync:

tests/unit/agentplatform/test_feature_group.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def fg_eq(
252252
def test_init(feature_group_name, get_fg_mock):
253253
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
254254

255-
fg = FeatureGroup(feature_group_name)
255+
fg = FeatureGroup(name=feature_group_name)
256256

257257
get_fg_mock.assert_called_once_with(
258258
name=_TEST_FG1_PATH,
@@ -415,7 +415,7 @@ def test_list(list_fg_mock):
415415
def test_delete(delete_fg_mock, get_fg_mock, fg_logger_mock, force, sync):
416416
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
417417

418-
fg = FeatureGroup(_TEST_FG1_ID)
418+
fg = FeatureGroup(name=_TEST_FG1_ID)
419419
fg.delete(force=force, sync=sync)
420420

421421
if not sync:
@@ -444,7 +444,7 @@ def test_delete(delete_fg_mock, get_fg_mock, fg_logger_mock, force, sync):
444444
def test_get_feature(get_fg_mock, get_feature_mock):
445445
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
446446

447-
fg = FeatureGroup(_TEST_FG1_ID)
447+
fg = FeatureGroup(name=_TEST_FG1_ID)
448448
feature = fg.get_feature(_TEST_FG1_F1_ID)
449449

450450
get_feature_mock.assert_called_once_with(
@@ -469,7 +469,7 @@ def test_get_feature_with_latest_stats_count(
469469
):
470470
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
471471

472-
fg = FeatureGroup(_TEST_FG1_ID)
472+
fg = FeatureGroup(name=_TEST_FG1_ID)
473473
feature = fg.get_feature(_TEST_FG1_F1_ID, latest_stats_count=1)
474474

475475
get_feature_with_stats_and_anomalies_mock.assert_called_once_with(
@@ -503,7 +503,7 @@ def test_get_feature_credentials_set_in_init(mock_base_instantiate_client):
503503
mock_base_instantiate_client.return_value.get_feature_group.return_value = _TEST_FG1
504504
mock_base_instantiate_client.return_value.get_feature.return_value = _TEST_FG1_F1
505505

506-
fg = FeatureGroup(_TEST_FG1_ID)
506+
fg = FeatureGroup(name=_TEST_FG1_ID)
507507
mock_base_instantiate_client.assert_called_with(
508508
location=_TEST_LOCATION,
509509
credentials=credentials,
@@ -538,7 +538,7 @@ def test_get_feature_from_feature_group_with_explicit_credentials(
538538
mock_base_instantiate_client.return_value.get_feature.return_value = _TEST_FG1_F1
539539

540540
credentials = mock.MagicMock(spec=auth_credentials.Credentials)
541-
fg = FeatureGroup(_TEST_FG1_ID, credentials=credentials)
541+
fg = FeatureGroup(name=_TEST_FG1_ID, credentials=credentials)
542542
mock_base_instantiate_client.assert_called_with(
543543
location=_TEST_LOCATION,
544544
credentials=credentials,
@@ -576,7 +576,7 @@ def test_get_feature_from_feature_group_with_explicit_credentials_overrides_init
576576
mock_base_instantiate_client.return_value.get_feature.return_value = _TEST_FG1_F1
577577

578578
credentials = mock.MagicMock(spec=auth_credentials.Credentials)
579-
fg = FeatureGroup(_TEST_FG1_ID, credentials=credentials)
579+
fg = FeatureGroup(name=_TEST_FG1_ID, credentials=credentials)
580580
mock_base_instantiate_client.assert_called_with(
581581
location=_TEST_LOCATION,
582582
credentials=credentials,
@@ -608,7 +608,7 @@ def test_get_feature_with_explicit_credentials(mock_base_instantiate_client):
608608
mock_base_instantiate_client.return_value.get_feature_group.return_value = _TEST_FG1
609609
mock_base_instantiate_client.return_value.get_feature.return_value = _TEST_FG1_F1
610610

611-
fg = FeatureGroup(_TEST_FG1_ID)
611+
fg = FeatureGroup(name=_TEST_FG1_ID)
612612
mock_base_instantiate_client.assert_called_with(
613613
location=_TEST_LOCATION,
614614
credentials=mock.ANY,
@@ -646,7 +646,7 @@ def test_get_feature_with_explicit_credentials_overrides_init_credentials(
646646
mock_base_instantiate_client.return_value.get_feature_group.return_value = _TEST_FG1
647647
mock_base_instantiate_client.return_value.get_feature.return_value = _TEST_FG1_F1
648648

649-
fg = FeatureGroup(_TEST_FG1_ID)
649+
fg = FeatureGroup(name=_TEST_FG1_ID)
650650
mock_base_instantiate_client.assert_called_with(
651651
location=_TEST_LOCATION,
652652
credentials=init_credentials,
@@ -682,7 +682,7 @@ def test_get_feature_with_explicit_credentials_overrides_feature_group_credentia
682682
mock_base_instantiate_client.return_value.get_feature.return_value = _TEST_FG1_F1
683683

684684
feature_group_credentials = mock.MagicMock(spec=auth_credentials.Credentials)
685-
fg = FeatureGroup(_TEST_FG1_ID, credentials=feature_group_credentials)
685+
fg = FeatureGroup(name=_TEST_FG1_ID, credentials=feature_group_credentials)
686686
mock_base_instantiate_client.assert_called_with(
687687
location=_TEST_LOCATION,
688688
credentials=feature_group_credentials,
@@ -721,7 +721,7 @@ def test_get_feature_with_explicit_credentials_overrides_init_and_feature_group_
721721
mock_base_instantiate_client.return_value.get_feature.return_value = _TEST_FG1_F1
722722

723723
feature_group_credentials = mock.MagicMock(spec=auth_credentials.Credentials)
724-
fg = FeatureGroup(_TEST_FG1_ID, credentials=feature_group_credentials)
724+
fg = FeatureGroup(name=_TEST_FG1_ID, credentials=feature_group_credentials)
725725
mock_base_instantiate_client.assert_called_with(
726726
location=_TEST_LOCATION,
727727
credentials=feature_group_credentials,
@@ -760,7 +760,7 @@ def test_create_feature(
760760
):
761761
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
762762

763-
fg = FeatureGroup(_TEST_FG1_ID)
763+
fg = FeatureGroup(name=_TEST_FG1_ID)
764764
feature = fg.create_feature(
765765
_TEST_FG1_F1_ID,
766766
description=_TEST_FG1_F1_DESCRIPTION,
@@ -826,7 +826,7 @@ def test_create_feature_with_version_feature_column(
826826
):
827827
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
828828

829-
fg = FeatureGroup(_TEST_FG1_ID)
829+
fg = FeatureGroup(name=_TEST_FG1_ID)
830830
feature = fg.create_feature(
831831
_TEST_FG1_F2_ID,
832832
version_column_name=_TEST_FG1_F2_VERSION_COLUMN_NAME,
@@ -886,7 +886,7 @@ def test_create_feature_with_version_feature_column(
886886
def test_list_features(get_fg_mock, list_features_mock):
887887
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
888888

889-
features = FeatureGroup(_TEST_FG1_ID).list_features()
889+
features = FeatureGroup(name=_TEST_FG1_ID).list_features()
890890

891891
list_features_mock.assert_called_once_with(request={"parent": _TEST_FG1_PATH})
892892
assert len(features) == len(_TEST_FG1_FEATURE_LIST)
@@ -923,7 +923,7 @@ def test_create_feature_monitor(
923923
):
924924
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
925925

926-
fg = FeatureGroup(_TEST_FG1_ID)
926+
fg = FeatureGroup(name=_TEST_FG1_ID)
927927
feature_monitor = fg.create_feature_monitor(
928928
_TEST_FG1_FM1_ID,
929929
description=_TEST_FG1_FM1_DESCRIPTION,
@@ -997,7 +997,7 @@ def test_list_feature_monitors(
997997
):
998998
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
999999

1000-
feature_monitors = FeatureGroup(_TEST_FG1_ID).list_feature_monitors()
1000+
feature_monitors = FeatureGroup(name=_TEST_FG1_ID).list_feature_monitors()
10011001

10021002
list_feature_monitors_mock.assert_called_once_with(
10031003
request={"parent": _TEST_FG1_PATH}

tests/unit/agentplatform/test_feature_monitor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_init_with_feature_monitor_id_and_no_fg_id_raises_error():
158158
" specify feature_group_id."
159159
),
160160
):
161-
FeatureMonitor(_TEST_FG1_FM1_ID)
161+
FeatureMonitor(name=_TEST_FG1_FM1_ID)
162162

163163

164164
def test_init_with_feature_monitor_path_and_fg_id_raises_error():
@@ -176,7 +176,7 @@ def test_init_with_feature_monitor_path_and_fg_id_raises_error():
176176
),
177177
):
178178
FeatureMonitor(
179-
_TEST_FG1_FM1_PATH,
179+
name=_TEST_FG1_FM1_PATH,
180180
feature_group_id=_TEST_FG1_ID,
181181
)
182182

@@ -216,7 +216,7 @@ def test_init_with_feature_monitor_path(get_feature_monitor_mock):
216216
location=_TEST_LOCATION,
217217
)
218218

219-
feature_monitor = FeatureMonitor(_TEST_FG1_FM1_PATH)
219+
feature_monitor = FeatureMonitor(name=_TEST_FG1_FM1_PATH)
220220

221221
get_feature_monitor_mock.assert_called_once_with(
222222
name=_TEST_FG1_FM1_PATH,
@@ -242,7 +242,7 @@ def test_init_with_feature_monitor_job_path(get_feature_monitor_job_mock):
242242
location=_TEST_LOCATION,
243243
)
244244

245-
feature_monitor_job = FeatureMonitor.FeatureMonitorJob(_TEST_FG1_FMJ1_PATH)
245+
feature_monitor_job = FeatureMonitor.FeatureMonitorJob(name=_TEST_FG1_FMJ1_PATH)
246246

247247
get_feature_monitor_job_mock.assert_called_once_with(
248248
name=_TEST_FG1_FMJ1_PATH,
@@ -274,7 +274,7 @@ def test_create_feature_monitor_job(
274274
)
275275

276276
fm = FeatureMonitor(
277-
_TEST_FG1_FM1_ID,
277+
name=_TEST_FG1_FM1_ID,
278278
feature_group_id=_TEST_FG1_ID,
279279
)
280280
feature_monitor_job = fm.create_feature_monitor_job(
@@ -314,7 +314,7 @@ def test_get_feature_monitor_job(
314314
)
315315

316316
fm = FeatureMonitor(
317-
_TEST_FG1_FM1_ID,
317+
name=_TEST_FG1_FM1_ID,
318318
feature_group_id=_TEST_FG1_ID,
319319
)
320320
feature_monitor_job = fm.get_feature_monitor_job(_TEST_FG1_FMJ1_ID)
@@ -344,7 +344,7 @@ def test_list_feature_monitors_jobs(
344344
)
345345

346346
feature_monitor_jobs = FeatureMonitor(
347-
_TEST_FG1_FM1_ID,
347+
name=_TEST_FG1_FM1_ID,
348348
feature_group_id=_TEST_FG1_ID,
349349
).list_feature_monitor_jobs()
350350

tests/unit/agentplatform/test_feature_online_store.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def fos_eq(
150150
def test_init(online_store_name, get_fos_mock):
151151
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
152152

153-
fos = FeatureOnlineStore(online_store_name)
153+
fos = FeatureOnlineStore(name=online_store_name)
154154

155155
get_fos_mock.assert_called_once_with(
156156
name=_TEST_BIGTABLE_FOS1_PATH, retry=base._DEFAULT_RETRY
@@ -439,7 +439,7 @@ def test_list(list_fos_mock):
439439
def test_delete(force, delete_fos_mock, get_fos_mock, fos_logger_mock, sync=True):
440440
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
441441

442-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
442+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
443443
fos.delete(force=force, sync=sync)
444444

445445
if not sync:
@@ -467,7 +467,7 @@ def test_delete(force, delete_fos_mock, get_fos_mock, fos_logger_mock, sync=True
467467

468468
def test_create_fv_none_source_raises_error(get_fos_mock):
469469
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
470-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
470+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
471471

472472
with pytest.raises(
473473
ValueError,
@@ -478,7 +478,7 @@ def test_create_fv_none_source_raises_error(get_fos_mock):
478478

479479
def test_create_fv_wrong_object_type_raises_error(get_fos_mock):
480480
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
481-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
481+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
482482

483483
with pytest.raises(
484484
ValueError,
@@ -492,7 +492,7 @@ def test_create_fv_wrong_object_type_raises_error(get_fos_mock):
492492

493493
def test_create_bq_fv_bad_uri_raises_error(get_fos_mock):
494494
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
495-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
495+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
496496

497497
with pytest.raises(
498498
ValueError,
@@ -509,7 +509,7 @@ def test_create_bq_fv_bad_entity_id_columns_raises_error(
509509
entity_id_columns, get_fos_mock
510510
):
511511
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
512-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
512+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
513513

514514
with pytest.raises(
515515
ValueError,
@@ -526,7 +526,7 @@ def test_create_bq_fv_bad_entity_id_columns_raises_error(
526526
)
527527
def test_create_fr_fv_invalid_feature_name_raises_error(features, get_fos_mock):
528528
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
529-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
529+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
530530

531531
with pytest.raises(
532532
ValueError,
@@ -551,7 +551,7 @@ def test_create_bq_fv(
551551
fos_logger_mock,
552552
):
553553
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
554-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
554+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
555555

556556
fv = fos.create_feature_view(
557557
_TEST_FV1_ID,
@@ -613,7 +613,7 @@ def test_create_embedding_fv(
613613
get_optimized_embedding_fv_mock,
614614
):
615615
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
616-
fos = FeatureOnlineStore(_TEST_ESF_OPTIMIZED_FOS_ID)
616+
fos = FeatureOnlineStore(name=_TEST_ESF_OPTIMIZED_FOS_ID)
617617

618618
embedding_fv = fos.create_feature_view(
619619
_TEST_OPTIMIZED_EMBEDDING_FV_ID,
@@ -639,7 +639,7 @@ def test_create_embedding_fv(
639639

640640
def test_create_rag_fv_bad_uri_raises_error(get_fos_mock):
641641
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
642-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
642+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
643643

644644
with pytest.raises(
645645
ValueError,
@@ -662,7 +662,7 @@ def test_create_rag_fv(
662662
fos_logger_mock,
663663
):
664664
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
665-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
665+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
666666

667667
rag_fv = fos.create_feature_view(
668668
_TEST_FV3_ID,
@@ -729,7 +729,7 @@ def test_create_registry_fv(
729729
fos_logger_mock,
730730
):
731731
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
732-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
732+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
733733

734734
registry_fv = fos.create_feature_view(
735735
_TEST_FV4_ID,
@@ -807,7 +807,7 @@ def test_list_feature_views(
807807
):
808808
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)
809809

810-
fos = FeatureOnlineStore(_TEST_BIGTABLE_FOS1_ID)
810+
fos = FeatureOnlineStore(name=_TEST_BIGTABLE_FOS1_ID)
811811
feature_views = fos.list_feature_views()
812812

813813
list_fv_mock.assert_called_once_with(request={"parent": _TEST_BIGTABLE_FOS1_PATH})

0 commit comments

Comments
 (0)