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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
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 number | Diff line number | Diff line change |
|---|
@@ -186,6 +186,21 @@ To run these tests: |
186 | 186 | # run the python API tests: |
187 | 187 | tox -e py_func_v4 |
188 | 188 |
|
| 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 | +
|
189 | 204 | By default, the tests run against the latest version of the ``gitlab/gitlab-ce`` |
190 | 205 | image. You can override both the image and tag by providing either the |
191 | 206 | ``GITLAB_IMAGE`` or ``GITLAB_TAG`` environment variables. |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/functional/conftest.py +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,6 +50,14 @@ def pytest_report_collectionfinish(config, startdir, items): |
50 | 50 | ] |
51 | 51 |
|
52 | 52 |
|
| 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 | + |
53 | 61 | @pytest.fixture(scope="session") |
54 | 62 | def temp_dir(): |
55 | 63 | return Path(tempfile.gettempdir()) |
@@ -65,6 +73,21 @@ def docker_compose_file(test_dir): |
65 | 73 | return test_dir / "fixtures" / "docker-compose.yml" |
66 | 74 |
|
67 | 75 |
|
| 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 | + |
68 | 91 | @pytest.fixture(scope="session") |
69 | 92 | def check_is_alive(): |
70 | 93 | """ |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/functional/fixtures/set_token.rb +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
2 | 2 |
|
3 | 3 | user = User.find_by_username('root') |
4 | 4 |
|
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'); |
6 | 6 | token.set_token('python-gitlab-token'); |
7 | 7 | token.save! |
8 | 8 |
|
|