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

Commita1ac9ae

Browse files
chore: add logging totests/functional/conftest.py
I have found trying to debug issues in the functional tests can bedifficult. Especially when trying to figure out failures in the CIrunning on Github.Add logging to `tests/functional/conftest.py` to have a betterunderstanding of what is happening during a test run which is usefulwhen trying to troubleshoot issues in the CI.
1 parent0dba899 commita1ac9ae

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
-name:Run tests
7474
env:
7575
TOXENV:${{ matrix.toxenv }}
76-
run:tox
76+
run:tox -- --override-ini='log_cli=True'
7777
-name:Upload codecov coverage
7878
uses:codecov/codecov-action@v2
7979
with:

‎pyproject.toml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@ disable = [
9090

9191
[tool.pytest.ini_options]
9292
xfail_strict =true
93+
94+
# If 'log_cli=True' the following apply
95+
# NOTE: If set 'log_cli_level' to 'DEBUG' will show a log of all of the HTTP requests
96+
# made in functional tests.
97+
log_cli_level ="INFO"
98+
log_cli_format ="%(asctime)s.%(msecs)03d [%(levelname)8s] (%(filename)s:%(funcName)s:L%(lineno)s) %(message)s"
99+
log_cli_date_format ="%Y-%m-%d %H:%M:%S"

‎tests/functional/conftest.py‎

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importlogging
12
importtempfile
23
importtime
34
importuuid
@@ -9,7 +10,7 @@
910
importgitlab
1011
importgitlab.base
1112

12-
SLEEP_INTERVAL=0.1
13+
SLEEP_INTERVAL=0.5
1314
TIMEOUT=60# seconds before timeout will occur
1415

1516

@@ -21,47 +22,69 @@ def fixture_dir(test_dir):
2122
defreset_gitlab(gl):
2223
# previously tools/reset_gitlab.py
2324
forprojectingl.projects.list():
25+
logging.info(f"Marking for deletion project:{project.path_with_namespace!r}")
2426
fordeploy_tokeninproject.deploytokens.list():
27+
logging.info(
28+
f"Marking for deletion token:{deploy_token.username!r} in "
29+
f"project:{project.path_with_namespace!r}"
30+
)
2531
deploy_token.delete()
2632
project.delete()
2733
forgroupingl.groups.list():
34+
logging.info(f"Marking for deletion group:{group.full_path!r}")
2835
fordeploy_tokeningroup.deploytokens.list():
36+
logging.info(
37+
f"Marking for deletion token:{deploy_token.username!r} in "
38+
f"group:{group.path_with_namespace!r}"
39+
)
2940
deploy_token.delete()
3041
group.delete()
3142
forvariableingl.variables.list():
43+
logging.info(f"Marking for deletion variable:{variable.key!r}")
3244
variable.delete()
3345
foruseringl.users.list():
3446
ifuser.username!="root":
47+
logging.info(f"Marking for deletion user:{user.username!r}")
3548
user.delete(hard_delete=True)
3649

3750
max_iterations=int(TIMEOUT/SLEEP_INTERVAL)
3851

3952
# Ensure everything has been reset
4053
start_time=time.perf_counter()
4154

42-
defwait_for_maximum_list_length(
55+
defwait_for_list_size(
4356
rest_manager:gitlab.base.RESTManager,description:str,max_length:int=0
4457
)->None:
4558
"""Wait for the list() length to be no greater than expected maximum or fail
4659
test if timeout is exceeded"""
47-
for_inrange(max_iterations):
48-
iflen(rest_manager.list())<=max_length:
60+
logging.info(f"Checking{description!r} has no more than{max_length} items")
61+
forcountinrange(max_iterations):
62+
items=rest_manager.list()
63+
iflen(items)<=max_length:
4964
break
65+
logging.info(
66+
f"Iteration:{count} Waiting for{description!r} items to be deleted: "
67+
f"{[x.nameforxinitems]}"
68+
)
5069
time.sleep(SLEEP_INTERVAL)
51-
assertlen(rest_manager.list())<=max_length, (
52-
f"Did not delete required items for{description}. "
53-
f"Elapsed_time:{time.perf_counter()-start_time}"
70+
71+
elapsed_time=time.perf_counter()-start_time
72+
error_message= (
73+
f"More than{max_length}{description!r} items still remaining and timeout "
74+
f"({elapsed_time}) exceeded:{[x.nameforxinitems]}"
5475
)
76+
iflen(items)>max_length:
77+
logging.error(error_message)
78+
assertlen(items)<=max_length,error_message
5579

56-
wait_for_maximum_list_length(rest_manager=gl.projects,description="projects")
57-
wait_for_maximum_list_length(rest_manager=gl.groups,description="groups")
58-
wait_for_maximum_list_length(rest_manager=gl.variables,description="variables")
59-
wait_for_maximum_list_length(
60-
rest_manager=gl.users,description="users",max_length=1
61-
)
80+
wait_for_list_size(rest_manager=gl.projects,description="projects")
81+
wait_for_list_size(rest_manager=gl.groups,description="groups")
82+
wait_for_list_size(rest_manager=gl.variables,description="variables")
83+
wait_for_list_size(rest_manager=gl.users,description="users",max_length=1)
6284

6385

6486
defset_token(container,fixture_dir):
87+
logging.info("Creating API token.")
6588
set_token_rb=fixture_dir/"set_token.rb"
6689

6790
withopen(set_token_rb,"r")asf:
@@ -76,6 +99,7 @@ def set_token(container, fixture_dir):
7699
set_token_command,
77100
]
78101
output=check_output(rails_command).decode().strip()
102+
logging.info("Finished creating API token.")
79103

80104
returnoutput
81105

@@ -85,7 +109,7 @@ def pytest_report_collectionfinish(config, startdir, items):
85109
"",
86110
"Starting GitLab container.",
87111
"Waiting for GitLab to reconfigure.",
88-
"Thismay take a few minutes.",
112+
"Thiswill take a few minutes.",
89113
]
90114

91115

@@ -129,6 +153,7 @@ def check_is_alive():
129153
"""
130154

131155
def_check(container):
156+
logging.info("Checking if GitLab container is up...")
132157
logs= ["docker","logs",container]
133158
return"gitlab Reconfigured!"incheck_output(logs).decode()
134159

@@ -144,7 +169,7 @@ def wait_for_sidekiq(gl):
144169
"""
145170

146171
def_wait(timeout=30,step=0.5):
147-
for_inrange(timeout):
172+
forcountinrange(timeout):
148173
time.sleep(step)
149174
busy=False
150175
processes=gl.sidekiq.process_metrics()["processes"]
@@ -153,6 +178,7 @@ def _wait(timeout=30, step=0.5):
153178
busy=True
154179
ifnotbusy:
155180
returnTrue
181+
logging.info(f"sidekiq busy{count} of{timeout}")
156182
returnFalse
157183

158184
return_wait
@@ -163,9 +189,11 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_
163189
config_file=temp_dir/"python-gitlab.cfg"
164190
port=docker_services.port_for("gitlab",80)
165191

192+
logging.info("Waiting for GitLab container to become ready.")
166193
docker_services.wait_until_responsive(
167-
timeout=200,pause=5,check=lambda:check_is_alive("gitlab-test")
194+
timeout=200,pause=10,check=lambda:check_is_alive("gitlab-test")
168195
)
196+
logging.info("GitLab container is now ready.")
169197

170198
token=set_token("gitlab-test",fixture_dir=fixture_dir)
171199

@@ -188,7 +216,9 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_
188216
defgl(gitlab_config):
189217
"""Helper instance to make fixtures and asserts directly via the API."""
190218

219+
logging.info("Instantiating python-gitlab gitlab.Gitlab instance")
191220
instance=gitlab.Gitlab.from_config("local", [gitlab_config])
221+
192222
reset_gitlab(instance)
193223

194224
returninstance

‎tox.ini‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ skipsdist = True
44
envlist = py310,py39,py38,py37,pep8,black,twine-check,mypy,isort
55

66
[testenv]
7-
passenv = GITLAB_IMAGE GITLAB_TAG
7+
passenv = GITLAB_IMAGE GITLAB_TAG PY_COLORS NO_COLOR FORCE_COLOR
88
setenv =VIRTUAL_ENV={envdir}
99
whitelist_externals = true
1010
usedevelop = True

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp