diff --git a/tests/functional/api/test_gitlab.py b/tests/functional/api/test_gitlab.py index c2aba09eb..ced77c272 100644 --- a/tests/functional/api/test_gitlab.py +++ b/tests/functional/api/test_gitlab.py @@ -15,11 +15,9 @@ def get_all_kwargs(request): return request.param -def test_auth_from_config(gl, temp_dir): +def test_auth_from_config(gl, gitlab_config, temp_dir): """Test token authentication from config file""" - test_gitlab = gitlab.Gitlab.from_config( - config_files=[temp_dir / "python-gitlab.cfg"] - ) + test_gitlab = gitlab.Gitlab.from_config(config_files=[gitlab_config]) test_gitlab.auth() assert isinstance(test_gitlab.user, gitlab.v4.objects.CurrentUser) diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index d2ff5e0ab..c85b17226 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -236,15 +236,13 @@ def _wait(timeout: int = 30, step: float = 0.5, allow_fail: bool = False) -> boo @pytest.fixture(scope="session") -def gitlab_config( +def gitlab_token( check_is_alive, gitlab_container_name: str, gitlab_url: str, docker_services, - temp_dir: pathlib.Path, fixture_dir: pathlib.Path, -): - config_file = temp_dir / "python-gitlab.cfg" +) -> str: start_time = time.perf_counter() logging.info("Waiting for GitLab container to become ready.") @@ -263,7 +261,12 @@ def gitlab_config( f"GitLab container is now ready after {minutes} minute(s), {seconds} seconds" ) - token = set_token(gitlab_container_name, fixture_dir=fixture_dir) + return set_token(gitlab_container_name, fixture_dir=fixture_dir) + + +@pytest.fixture(scope="session") +def gitlab_config(gitlab_url: str, gitlab_token: str, temp_dir: pathlib.Path): + config_file = temp_dir / "python-gitlab.cfg" config = f"""[global] default = local @@ -271,7 +274,7 @@ def gitlab_config( [local] url = {gitlab_url} -private_token = {token} +private_token = {gitlab_token} api_version = 4""" with open(config_file, "w", encoding="utf-8") as f: @@ -281,11 +284,11 @@ def gitlab_config( @pytest.fixture(scope="session") -def gl(gitlab_config): +def gl(gitlab_url: str, gitlab_token: str) -> gitlab.Gitlab: """Helper instance to make fixtures and asserts directly via the API.""" logging.info("Instantiating python-gitlab gitlab.Gitlab instance") - instance = gitlab.Gitlab.from_config("local", [gitlab_config]) + instance = gitlab.Gitlab(gitlab_url, private_token=gitlab_token) logging.info("Reset GitLab") reset_gitlab(instance)