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

Commitd981956

Browse files
authored
Merge pull request#1478 from benjamb/benbrown/keep-containers
Optionally keep containers after running integration tests
2 parents55ae61a +4e690c2 commitd981956

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed

‎README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ To run these tests:
186186
# run the python API tests:
187187
tox -e py_func_v4
188188
189+
When developing tests it can be a little frustrating to wait for GitLab to spin
190+
up every run. To prevent the containers from being cleaned up afterwards, pass
191+
`--keep-containers` to pytest, i.e.:
192+
193+
..code-block::bash
194+
195+
tox -e py_func_v4 -- --keep-containers
196+
197+
If you then wish to test against a clean slate, you may perform a manual clean
198+
up of the containers by running:
199+
200+
..code-block::bash
201+
202+
docker-compose -f tests/functional/fixtures/docker-compose.yml -p pytest-python-gitlab down -v
203+
189204
By default, the tests run against the latest version of the ``gitlab/gitlab-ce``
190205
image. You can override both the image and tag by providing either the
191206
``GITLAB_IMAGE`` or ``GITLAB_TAG`` environment variables.

‎gitlab/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def http_put(
787787
)frome
788788

789789
defhttp_delete(self,path:str,**kwargs:Any)->requests.Response:
790-
"""Make aPUT request to the Gitlab server.
790+
"""Make aDELETE request to the Gitlab server.
791791
792792
Args:
793793
path (str): Path or full URL to query ('/projects' or

‎gitlab/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def delete(self, **kwargs: Any) -> None:
576576
"""
577577
ifTYPE_CHECKING:
578578
assertisinstance(self.manager,DeleteMixin)
579-
self.manager.delete(self.get_id())
579+
self.manager.delete(self.get_id(),**kwargs)
580580

581581

582582
classUserAgentDetailMixin(_RestObjectBase):

‎tests/functional/api/test_issues.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
deftest_create_issue(project):
55
issue=project.issues.create({"title":"my issue 1"})
66
issue2=project.issues.create({"title":"my issue 2"})
7-
issue_ids= [issue.idforissueinproject.issues.list()]
8-
assertlen(issue_ids)==2
7+
issue_iids= [issue.iidforissueinproject.issues.list()]
8+
assertlen(issue_iids)==2
99

1010
# Test 'iids' as a list
11-
assertlen(project.issues.list(iids=issue_ids))==2
11+
assertlen(project.issues.list(iids=issue_iids))==2
1212

1313
issue2.state_event="close"
1414
issue2.save()

‎tests/functional/cli/test_cli_artifacts.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
importsubprocess
2-
importsys
32
importtextwrap
43
importtime
54
fromioimportBytesIO
65
fromzipfileimportis_zipfile
76

8-
importpytest
9-
107
content=textwrap.dedent(
118
"""\
129
test-artifact:
@@ -23,11 +20,12 @@
2320
}
2421

2522

26-
@pytest.mark.skipif(sys.version_info< (3,8),reason="I am the walrus")
2723
deftest_cli_artifacts(capsysbinary,gitlab_config,gitlab_runner,project):
2824
project.files.create(data)
2925

30-
whilenot (jobs:=project.jobs.list(scope="success")):
26+
jobs=None
27+
whilenotjobs:
28+
jobs=project.jobs.list(scope="success")
3129
time.sleep(0.5)
3230

3331
job=project.jobs.get(jobs[0].id)

‎tests/functional/conftest.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
defreset_gitlab(gl):
1313
# previously tools/reset_gitlab.py
1414
forprojectingl.projects.list():
15+
fordeploy_tokeninproject.deploytokens.list():
16+
deploy_token.delete()
1517
project.delete()
1618
forgroupingl.groups.list():
19+
fordeploy_tokeningroup.deploytokens.list():
20+
deploy_token.delete()
1721
group.delete()
1822
forvariableingl.variables.list():
1923
variable.delete()
2024
foruseringl.users.list():
2125
ifuser.username!="root":
22-
user.delete()
26+
user.delete(hard_delete=True)
2327

2428

2529
defset_token(container,rootdir):
@@ -50,6 +54,14 @@ def pytest_report_collectionfinish(config, startdir, items):
5054
]
5155

5256

57+
defpytest_addoption(parser):
58+
parser.addoption(
59+
"--keep-containers",
60+
action="store_true",
61+
help="Keep containers running after testing",
62+
)
63+
64+
5365
@pytest.fixture(scope="session")
5466
deftemp_dir():
5567
returnPath(tempfile.gettempdir())
@@ -65,6 +77,21 @@ def docker_compose_file(test_dir):
6577
returntest_dir/"fixtures"/"docker-compose.yml"
6678

6779

80+
@pytest.fixture(scope="session")
81+
defdocker_compose_project_name():
82+
"""Set a consistent project name to enable optional reuse of containers."""
83+
return"pytest-python-gitlab"
84+
85+
86+
@pytest.fixture(scope="session")
87+
defdocker_cleanup(request):
88+
"""Conditionally keep containers around by overriding the cleanup command."""
89+
ifrequest.config.getoption("--keep-containers"):
90+
# Print version and exit.
91+
return"-v"
92+
return"down -v"
93+
94+
6895
@pytest.fixture(scope="session")
6996
defcheck_is_alive():
7097
"""

‎tests/functional/fixtures/set_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
user=User.find_by_username('root')
44

5-
token=user.personal_access_tokens.create(scopes:[:api,:sudo],name:'default');
5+
token=user.personal_access_tokens.first_or_create(scopes:[:api,:sudo],name:'default');
66
token.set_token('python-gitlab-token');
77
token.save!
88

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp