GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(functional): optionally keep containers running post-tests · python-gitlab/python-gitlab@4c475ab

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.rst
  • tests/functional
    • conftest.py
    • fixtures
      • set_token.rb
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.rst‎

Copy file name to clipboardExpand all lines: README.rst
+15Lines changed: 15 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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.
Collapse file

‎tests/functional/conftest.py‎

Copy file name to clipboardExpand all lines: tests/functional/conftest.py
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def pytest_report_collectionfinish(config, startdir, items):
5050
]
5151

5252

53+
def pytest_addoption(parser):
54+
parser.addoption(
55+
"--keep-containers",
56+
action="store_true",
57+
help="Keep containers running after testing",
58+
)
59+
60+
5361
@pytest.fixture(scope="session")
5462
def temp_dir():
5563
return Path(tempfile.gettempdir())
@@ -65,6 +73,21 @@ def docker_compose_file(test_dir):
6573
return test_dir / "fixtures" / "docker-compose.yml"
6674

6775

76+
@pytest.fixture(scope="session")
77+
def docker_compose_project_name():
78+
"""Set a consistent project name to enable optional reuse of containers."""
79+
return "pytest-python-gitlab"
80+
81+
82+
@pytest.fixture(scope="session")
83+
def docker_cleanup(request):
84+
"""Conditionally keep containers around by overriding the cleanup command."""
85+
if request.config.getoption("--keep-containers"):
86+
# Print version and exit.
87+
return "-v"
88+
return "down -v"
89+
90+
6891
@pytest.fixture(scope="session")
6992
def check_is_alive():
7093
"""
Collapse file

‎tests/functional/fixtures/set_token.rb‎

Copy file name to clipboardExpand all lines: tests/functional/fixtures/set_token.rb
+1-1Lines 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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.