@@ -158,6 +158,22 @@ def _wait(timeout=30, step=0.5):
158
158
return _wait
159
159
160
160
161
+ def wait_for_deleted (
162
+ * , pg_manager : gitlab .base .RESTManager , object_id : int , description : str
163
+ ) -> None :
164
+ """Ensure the object specified can not be retrieved. If object still exists after
165
+ timeout period, fail the test"""
166
+ max_iterations = int (TIMEOUT / SLEEP_INTERVAL )
167
+
168
+ for _ in range (max_iterations ):
169
+ try :
170
+ pg_manager .get (object_id )
171
+ except gitlab .exceptions .GitlabGetError :
172
+ return
173
+ time .sleep (SLEEP_INTERVAL )
174
+ pytest .fail (f"{ description } { object_id } was not deleted" )
175
+
176
+
161
177
@pytest .fixture (scope = "session" )
162
178
def gitlab_config (check_is_alive , docker_ip , docker_services , temp_dir , fixture_dir ):
163
179
config_file = temp_dir / "python-gitlab.cfg"
@@ -233,6 +249,7 @@ def group(gl):
233
249
"path" : f"group-{ _id } " ,
234
250
}
235
251
group = gl .groups .create (data )
252
+ group_id = group .id
236
253
237
254
yield group
238
255
@@ -241,6 +258,8 @@ def group(gl):
241
258
except gitlab .exceptions .GitlabDeleteError as e :
242
259
print (f"Group already deleted: { e } " )
243
260
261
+ wait_for_deleted (pg_manager = gl .groups , object_id = group_id , description = "Group" )
262
+
244
263
245
264
@pytest .fixture (scope = "module" )
246
265
def project (gl ):
@@ -249,6 +268,7 @@ def project(gl):
249
268
name = f"test-project-{ _id } "
250
269
251
270
project = gl .projects .create (name = name )
271
+ project_id = project .id
252
272
253
273
yield project
254
274
@@ -257,6 +277,10 @@ def project(gl):
257
277
except gitlab .exceptions .GitlabDeleteError as e :
258
278
print (f"Project already deleted: { e } " )
259
279
280
+ wait_for_deleted (
281
+ pg_manager = gl .projects , object_id = project_id , description = "Project"
282
+ )
283
+
260
284
261
285
@pytest .fixture (scope = "function" )
262
286
def merge_request (project , wait_for_sidekiq ):
@@ -328,6 +352,18 @@ def _merge_request(*, source_branch: str):
328
352
# Ignore if branch was already deleted
329
353
pass
330
354
355
+ for mr_iid , source_branch in to_delete :
356
+ wait_for_deleted (
357
+ pg_manager = project .mergerequests ,
358
+ object_id = mr_iid ,
359
+ description = "Project mergerequest" ,
360
+ )
361
+ wait_for_deleted (
362
+ pg_manager = project .branches ,
363
+ object_id = source_branch ,
364
+ description = "Project branch" ,
365
+ )
366
+
331
367
332
368
@pytest .fixture (scope = "module" )
333
369
def project_file (project ):
@@ -372,6 +408,7 @@ def user(gl):
372
408
password = "fakepassword"
373
409
374
410
user = gl .users .create (email = email , username = username , name = name , password = password )
411
+ user_id = user .id
375
412
376
413
yield user
377
414
@@ -380,6 +417,8 @@ def user(gl):
380
417
except gitlab .exceptions .GitlabDeleteError as e :
381
418
print (f"User already deleted: { e } " )
382
419
420
+ wait_for_deleted (pg_manager = gl .users , object_id = user_id , description = "User" )
421
+
383
422
384
423
@pytest .fixture (scope = "module" )
385
424
def issue (project ):
0 commit comments