Skip to content

Commit 29488e6

Browse files
committed
chore: remove unnecessary random function
1 parent 8eab0d5 commit 29488e6

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

tools/functional/conftest.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import time
21
import tempfile
2+
import time
3+
import uuid
34
from pathlib import Path
45
from random import randint
56
from subprocess import check_output
@@ -13,16 +14,6 @@
1314
TEST_DIR = Path(__file__).resolve().parent
1415

1516

16-
def random_id():
17-
"""
18-
Helper to ensure new resource creation does not clash with
19-
existing resources, for example when a previous test deleted a
20-
resource but GitLab is still deleting it asynchronously in the
21-
background. TODO: Expand to make it 100% safe.
22-
"""
23-
return randint(9, 9999)
24-
25-
2617
def reset_gitlab(gl):
2718
# previously tools/reset_gitlab.py
2819
for project in gl.projects.list():
@@ -125,7 +116,7 @@ def gl(gitlab_config):
125116
@pytest.fixture(scope="module")
126117
def group(gl):
127118
"""Group fixture for group API resource tests."""
128-
_id = random_id()
119+
_id = uuid.uuid4().hex
129120
data = {
130121
"name": f"test-group-{_id}",
131122
"path": f"group-{_id}",
@@ -143,7 +134,7 @@ def group(gl):
143134
@pytest.fixture(scope="module")
144135
def project(gl):
145136
"""Project fixture for project API resource tests."""
146-
_id = random_id()
137+
_id = uuid.uuid4().hex
147138
name = f"test-project-{_id}"
148139

149140
project = gl.projects.create(name=name)
@@ -159,7 +150,7 @@ def project(gl):
159150
@pytest.fixture(scope="module")
160151
def user(gl):
161152
"""User fixture for user API resource tests."""
162-
_id = random_id()
153+
_id = uuid.uuid4().hex
163154
email = f"user{_id}@email.com"
164155
username = f"user{_id}"
165156
name = f"User {_id}"
@@ -178,7 +169,7 @@ def user(gl):
178169
@pytest.fixture(scope="module")
179170
def issue(project):
180171
"""Issue fixture for issue API resource tests."""
181-
_id = random_id()
172+
_id = uuid.uuid4().hex
182173
data = {"title": f"Issue {_id}", "description": f"Issue {_id} description"}
183174

184175
return project.issues.create(data)
@@ -187,7 +178,7 @@ def issue(project):
187178
@pytest.fixture(scope="module")
188179
def label(project):
189180
"""Label fixture for project label API resource tests."""
190-
_id = random_id()
181+
_id = uuid.uuid4().hex
191182
data = {
192183
"name": f"prjlabel{_id}",
193184
"description": f"prjlabel1 {_id} description",
@@ -200,7 +191,7 @@ def label(project):
200191
@pytest.fixture(scope="module")
201192
def group_label(group):
202193
"""Label fixture for group label API resource tests."""
203-
_id = random_id()
194+
_id = uuid.uuid4().hex
204195
data = {
205196
"name": f"grplabel{_id}",
206197
"description": f"grplabel1 {_id} description",
@@ -213,7 +204,7 @@ def group_label(group):
213204
@pytest.fixture(scope="module")
214205
def variable(project):
215206
"""Variable fixture for project variable API resource tests."""
216-
_id = random_id()
207+
_id = uuid.uuid4().hex
217208
data = {"key": f"var{_id}", "value": f"Variable {_id}"}
218209

219210
return project.variables.create(data)
@@ -222,7 +213,7 @@ def variable(project):
222213
@pytest.fixture(scope="module")
223214
def deploy_token(project):
224215
"""Deploy token fixture for project deploy token API resource tests."""
225-
_id = random_id()
216+
_id = uuid.uuid4().hex
226217
data = {
227218
"name": f"token-{_id}",
228219
"username": "root",
@@ -236,7 +227,7 @@ def deploy_token(project):
236227
@pytest.fixture(scope="module")
237228
def group_deploy_token(group):
238229
"""Deploy token fixture for group deploy token API resource tests."""
239-
_id = random_id()
230+
_id = uuid.uuid4().hex
240231
data = {
241232
"name": f"group-token-{_id}",
242233
"username": "root",

0 commit comments

Comments
 (0)