1212def reset_gitlab (gl ):
1313 # previously tools/reset_gitlab.py
1414 for project in gl .projects .list ():
15+ for deploy_token in project .deploytokens .list ():
16+ deploy_token .delete ()
1517 project .delete ()
1618 for group in gl .groups .list ():
19+ for deploy_token in group .deploytokens .list ():
20+ deploy_token .delete ()
1721 group .delete ()
1822 for variable in gl .variables .list ():
1923 variable .delete ()
2024 for user in gl .users .list ():
2125 if user .username != "root" :
22- user .delete ()
26+ user .delete (hard_delete = True )
2327
2428
2529def set_token (container , rootdir ):
@@ -50,6 +54,14 @@ def pytest_report_collectionfinish(config, startdir, items):
5054 ]
5155
5256
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+
5365@pytest .fixture (scope = "session" )
5466def temp_dir ():
5567 return Path (tempfile .gettempdir ())
@@ -65,6 +77,21 @@ def docker_compose_file(test_dir):
6577 return test_dir / "fixtures" / "docker-compose.yml"
6678
6779
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+
6895@pytest .fixture (scope = "session" )
6996def check_is_alive ():
7097 """
0 commit comments