Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: always ensure clean config environment#2187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JohnVillalovos merged 1 commit intomainfromtest/clean-config
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletionstests/conftest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
importpytest

importgitlab


@pytest.fixture(scope="session")
deftest_dir(pytestconfig):
returnpytestconfig.rootdir/"tests"


@pytest.fixture(autouse=True)
defmock_clean_config(monkeypatch):
"""Ensures user-defined environment variables do not interfere with tests."""
monkeypatch.delenv("PYTHON_GITLAB_CFG",raising=False)
monkeypatch.delenv("GITLAB_PRIVATE_TOKEN",raising=False)
monkeypatch.delenv("GITLAB_URL",raising=False)
monkeypatch.delenv("CI_JOB_TOKEN",raising=False)
monkeypatch.delenv("CI_SERVER_URL",raising=False)


@pytest.fixture(autouse=True)
defdefault_files(monkeypatch):
"""Ensures user configuration files do not interfere with tests."""
monkeypatch.setattr(gitlab.config,"_DEFAULT_FILES", [])


@pytest.fixture
defvalid_gitlab_ci_yml():
return"""---
Expand Down
6 changes: 1 addition & 5 deletionstests/functional/cli/test_cli_variables.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@
import pytest
import responses

from gitlab import config
from gitlab.const import DEFAULT_URL


Expand DownExpand Up@@ -37,10 +36,7 @@ def test_list_project_variables_with_path(gitlab_cli, project):

@pytest.mark.script_launch_mode("inprocess")
@responses.activate
def test_list_project_variables_with_path_url_check(
monkeypatch, script_runner, resp_get_project
):
monkeypatch.setattr(config, "_DEFAULT_FILES", [])
def test_list_project_variables_with_path_url_check(script_runner, resp_get_project):
resp_get_project_variables = copy.deepcopy(resp_get_project)
resp_get_project_variables.update(
url=f"{DEFAULT_URL}/api/v4/projects/project%2Fwith%2Fa%2Fnamespace/variables"
Expand Down
17 changes: 9 additions & 8 deletionstests/unit/test_config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,6 +100,12 @@
"""


@pytest.fixture(autouse=True)
def default_files(monkeypatch):
"""Overrides mocked default files from conftest.py as we have our own mocks here."""
monkeypatch.setattr(gitlab.config, "_DEFAULT_FILES", config._DEFAULT_FILES)


def global_retry_transient_errors(value: bool) -> str:
return f"""[global]
default = one
Expand DownExpand Up@@ -129,24 +135,19 @@ def _mock_existent_file(path, *args, **kwargs):
return path


@pytest.fixture
def mock_clean_env(monkeypatch):
monkeypatch.delenv("PYTHON_GITLAB_CFG", raising=False)


def test_env_config_missing_file_raises(monkeypatch):
monkeypatch.setenv("PYTHON_GITLAB_CFG", "/some/path")
with pytest.raises(config.GitlabConfigMissingError):
config._get_config_files()


def test_env_config_not_defined_does_not_raise(mock_clean_env,monkeypatch):
def test_env_config_not_defined_does_not_raise(monkeypatch):
with monkeypatch.context() as m:
m.setattr(config, "_DEFAULT_FILES", [])
assert config._get_config_files() == []


def test_default_config(mock_clean_env,monkeypatch):
def test_default_config(monkeypatch):
with monkeypatch.context() as m:
m.setattr(Path, "resolve", _mock_nonexistent_file)
cp = config.GitlabConfigParser()
Expand All@@ -169,7 +170,7 @@ def test_default_config(mock_clean_env, monkeypatch):


@mock.patch("builtins.open")
def test_invalid_id(m_open,mock_clean_env,monkeypatch):
def test_invalid_id(m_open, monkeypatch):
fd = io.StringIO(no_default_config)
fd.close = mock.Mock(return_value=None)
m_open.return_value = fd
Expand Down
7 changes: 1 addition & 6 deletionstests/unit/test_gitlab.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,6 @@
import logging
import pickle
from http.client import HTTPConnection
from typing import List, Optional, Union

import pytest
import responses
Expand DownExpand Up@@ -301,11 +300,7 @@ def test_gitlab_from_config(default_config):
gitlab.Gitlab.from_config("one", [config_path])


def test_gitlab_from_config_without_files_raises(monkeypatch):
def no_files(config_files: Optional[List[str]] = None) -> Union[str, List[str]]:
return []

monkeypatch.setattr(gitlab.config, "_get_config_files", no_files)
def test_gitlab_from_config_without_files_raises():
with pytest.raises(GitlabConfigMissingError, match="non-existing"):
gitlab.Gitlab.from_config("non-existing")

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp