Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f73b6b

Browse files
chore: fixtures: after delete() wait to verify deleted
In our fixtures that create: - groups - project merge requests - projects - usersThey delete the created objects after use. Now wait to ensure theobjects are deleted before continuing as having unexpected objectsexisting can impact some of our tests.
1 parent201298d commit1f73b6b

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

‎tests/functional/conftest.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
importgitlab
1111
importgitlab.base
12-
13-
SLEEP_INTERVAL=0.5
14-
TIMEOUT=60# seconds before timeout will occur
12+
fromtests.functionalimporthelpers
1513

1614

1715
@pytest.fixture(scope="session")
@@ -49,8 +47,6 @@ def reset_gitlab(gl):
4947
logging.info(f"Marking for deletion user:{user.username!r}")
5048
user.delete(hard_delete=True)
5149

52-
max_iterations=int(TIMEOUT/SLEEP_INTERVAL)
53-
5450
# Ensure everything has been reset
5551
start_time=time.perf_counter()
5652

@@ -60,15 +56,15 @@ def wait_for_list_size(
6056
"""Wait for the list() length to be no greater than expected maximum or fail
6157
test if timeout is exceeded"""
6258
logging.info(f"Checking{description!r} has no more than{max_length} items")
63-
forcountinrange(max_iterations):
59+
forcountinrange(helpers.MAX_ITERATIONS):
6460
items=rest_manager.list()
6561
iflen(items)<=max_length:
6662
break
6763
logging.info(
6864
f"Iteration:{count} Waiting for{description!r} items to be deleted: "
6965
f"{[x.nameforxinitems]}"
7066
)
71-
time.sleep(SLEEP_INTERVAL)
67+
time.sleep(helpers.SLEEP_INTERVAL)
7268

7369
elapsed_time=time.perf_counter()-start_time
7470
error_message= (
@@ -280,10 +276,7 @@ def group(gl):
280276

281277
yieldgroup
282278

283-
try:
284-
group.delete()
285-
exceptgitlab.exceptions.GitlabDeleteErrorase:
286-
print(f"Group already deleted:{e}")
279+
helpers.safe_delete(group)
287280

288281

289282
@pytest.fixture(scope="module")
@@ -296,10 +289,7 @@ def project(gl):
296289

297290
yieldproject
298291

299-
try:
300-
project.delete()
301-
exceptgitlab.exceptions.GitlabDeleteErrorase:
302-
print(f"Project already deleted:{e}")
292+
helpers.safe_delete(project)
303293

304294

305295
@pytest.fixture(scope="function")
@@ -327,7 +317,7 @@ def _merge_request(*, source_branch: str):
327317
assertresultisTrue,"sidekiq process should have terminated but did not"
328318

329319
project.refresh()# Gets us the current default branch
330-
project.branches.create(
320+
mr_branch=project.branches.create(
331321
{"branch":source_branch,"ref":project.default_branch}
332322
)
333323
# NOTE(jlvillal): Must create a commit in the new branch before we can
@@ -359,18 +349,13 @@ def _merge_request(*, source_branch: str):
359349
time.sleep(0.5)
360350
assertmr.merge_status!="checking"
361351

362-
to_delete.append((mr.iid,source_branch))
352+
to_delete.extend([mr,mr_branch])
363353
returnmr
364354

365355
yield_merge_request
366356

367-
formr_iid,source_branchinto_delete:
368-
project.mergerequests.delete(mr_iid)
369-
try:
370-
project.branches.delete(source_branch)
371-
exceptgitlab.exceptions.GitlabDeleteError:
372-
# Ignore if branch was already deleted
373-
pass
357+
forobjectinto_delete:
358+
helpers.safe_delete(object)
374359

375360

376361
@pytest.fixture(scope="module")
@@ -434,11 +419,8 @@ def user(gl):
434419

435420
yielduser
436421

437-
try:
438-
# Use `hard_delete=True` or a 'Ghost User' may be created.
439-
user.delete(hard_delete=True)
440-
exceptgitlab.exceptions.GitlabDeleteErrorase:
441-
print(f"User already deleted:{e}")
422+
# Use `hard_delete=True` or a 'Ghost User' may be created.
423+
helpers.safe_delete(user,hard_delete=True)
442424

443425

444426
@pytest.fixture(scope="module")

‎tests/functional/helpers.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
importlogging
2+
importtime
3+
4+
importpytest
5+
6+
importgitlab.base
7+
8+
SLEEP_INTERVAL=0.5
9+
TIMEOUT=60# seconds before timeout will occur
10+
MAX_ITERATIONS=int(TIMEOUT/SLEEP_INTERVAL)
11+
12+
13+
defsafe_delete(
14+
object:gitlab.base.RESTObject,
15+
*,
16+
hard_delete:bool=False,
17+
)->None:
18+
"""Ensure the object specified can not be retrieved. If object still exists after
19+
timeout period, fail the test"""
20+
manager=object.manager
21+
forindexinrange(MAX_ITERATIONS):
22+
try:
23+
object=manager.get(object.get_id())
24+
exceptgitlab.exceptions.GitlabGetError:
25+
return
26+
27+
ifindex:
28+
logging.info(f"Attempt{index+1} to delete{object!r}.")
29+
try:
30+
ifhard_delete:
31+
object.delete(hard_delete=True)
32+
else:
33+
object.delete()
34+
exceptgitlab.exceptions.GitlabDeleteError:
35+
logging.info(f"{object!r} already deleted.")
36+
pass
37+
38+
time.sleep(SLEEP_INTERVAL)
39+
pytest.fail(f"{object!r} was not deleted")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp