| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ac92205 commit 4c475ab
3 files changed
| 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. | |
| 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 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments