12
12
def reset_gitlab (gl ):
13
13
# previously tools/reset_gitlab.py
14
14
for project in gl .projects .list ():
15
+ for deploy_token in project .deploytokens .list ():
16
+ deploy_token .delete ()
15
17
project .delete ()
16
18
for group in gl .groups .list ():
19
+ for deploy_token in group .deploytokens .list ():
20
+ deploy_token .delete ()
17
21
group .delete ()
18
22
for variable in gl .variables .list ():
19
23
variable .delete ()
20
24
for user in gl .users .list ():
21
25
if user .username != "root" :
22
- user .delete ()
26
+ user .delete (hard_delete = True )
23
27
24
28
25
29
def set_token (container , rootdir ):
@@ -50,6 +54,14 @@ def pytest_report_collectionfinish(config, startdir, items):
50
54
]
51
55
52
56
57
+ def pytest_addoption (parser ):
58
+ parser .addoption (
59
+ "--keep-containers" ,
60
+ action = "store_true" ,
61
+ help = "Keep containers running after testing" ,
62
+ )
63
+
64
+
53
65
@pytest .fixture (scope = "session" )
54
66
def temp_dir ():
55
67
return Path (tempfile .gettempdir ())
@@ -65,6 +77,21 @@ def docker_compose_file(test_dir):
65
77
return test_dir / "fixtures" / "docker-compose.yml"
66
78
67
79
80
+ @pytest .fixture (scope = "session" )
81
+ def docker_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
+ def docker_cleanup (request ):
88
+ """Conditionally keep containers around by overriding the cleanup command."""
89
+ if request .config .getoption ("--keep-containers" ):
90
+ # Print version and exit.
91
+ return "-v"
92
+ return "down -v"
93
+
94
+
68
95
@pytest .fixture (scope = "session" )
69
96
def check_is_alive ():
70
97
"""
0 commit comments