diff options
| author | Ben Brown <ben.brown@codethink.co.uk> | 2021-05-27 14:44:46 +0100 |
|---|---|---|
| committer | Ben Brown <ben.brown@codethink.co.uk> | 2021-06-01 15:03:28 +0100 |
| commit | 4c475abe30c36217da920477f3748e26f3395365 (patch) | |
| tree | 6f5e699355bd237b62276d7497621e735078f232 /tests/functional | |
| parent | ac922054eb22fcebf05526e8811d52770d34da53 (diff) | |
| download | gitlab-4c475abe30c36217da920477f3748e26f3395365.tar.gz | |
test(functional): optionally keep containers running post-tests
Additionally updates token creation to make use of `first_or_create()`,
to avoid errors from the script caused by GitLab constraints preventing
duplicate tokens with the same value.
Diffstat (limited to 'tests/functional')
| -rw-r--r-- | tests/functional/conftest.py | 23 | ||||
| -rw-r--r-- | tests/functional/fixtures/set_token.rb | 2 |
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 5d3b1b9..2c38b9f 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -50,6 +50,14 @@ def pytest_report_collectionfinish(config, startdir, items): ] +def pytest_addoption(parser): + parser.addoption( + "--keep-containers", + action="store_true", + help="Keep containers running after testing", + ) + + @pytest.fixture(scope="session") def temp_dir(): return Path(tempfile.gettempdir()) @@ -66,6 +74,21 @@ def docker_compose_file(test_dir): @pytest.fixture(scope="session") +def docker_compose_project_name(): + """Set a consistent project name to enable optional reuse of containers.""" + return "pytest-python-gitlab" + + +@pytest.fixture(scope="session") +def docker_cleanup(request): + """Conditionally keep containers around by overriding the cleanup command.""" + if request.config.getoption("--keep-containers"): + # Print version and exit. + return "-v" + return "down -v" + + +@pytest.fixture(scope="session") def check_is_alive(): """ Return a healthcheck function fixture for the GitLab container spinup. diff --git a/tests/functional/fixtures/set_token.rb b/tests/functional/fixtures/set_token.rb index 735dcd5..503588b 100644 --- a/tests/functional/fixtures/set_token.rb +++ b/tests/functional/fixtures/set_token.rb @@ -2,7 +2,7 @@ user = User.find_by_username('root') -token = user.personal_access_tokens.create(scopes: [:api, :sudo], name: 'default'); +token = user.personal_access_tokens.first_or_create(scopes: [:api, :sudo], name: 'default'); token.set_token('python-gitlab-token'); token.save! |
