Skip to content

Commit 8418915

Browse files
authored
Make test robuster to server state, avoid attaching attached runs (#1263)
It is not allowed to attach a run to a study which is already associated with the study. This leads to a misleading error: `1045: Problem attaching entities. Please ensure to only attach entities that exist - None`
1 parent 495162d commit 8418915

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

tests/test_study/test_study_functions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,19 @@ def test_publish_study(self):
187187
)
188188
self.assertSetEqual(set(run_ids), set(study_downloaded.runs))
189189

190-
# attach more runs
191-
run_list_additional = openml.runs.list_runs(size=10, offset=10)
192-
openml.study.attach_to_study(study.id, list(run_list_additional.keys()))
190+
# attach more runs, since we fetch 11 here, at least one is non-overlapping
191+
run_list_additional = openml.runs.list_runs(size=11, offset=10)
192+
run_list_additional = set(run_list_additional) - set(run_ids)
193+
openml.study.attach_to_study(study.id, list(run_list_additional))
193194
study_downloaded = openml.study.get_study(study.id)
194195
# verify again
195-
all_run_ids = set(run_list_additional.keys()) | set(run_list.keys())
196+
all_run_ids = run_list_additional | set(run_list.keys())
196197
self.assertSetEqual(set(study_downloaded.runs), all_run_ids)
197198

198199
# test detach function
199200
openml.study.detach_from_study(study.id, list(run_list.keys()))
200201
study_downloaded = openml.study.get_study(study.id)
201-
self.assertSetEqual(set(study_downloaded.runs), set(run_list_additional.keys()))
202+
self.assertSetEqual(set(study_downloaded.runs), run_list_additional)
202203

203204
# test status update function
204205
openml.study.update_study_status(study.id, "deactivated")

0 commit comments

Comments
 (0)