| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4b798fc commit 8d4f13b
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,29 @@ | |||
| 1 | 1 | import pytest | |
| 2 | 2 | ||
| 3 | + import gitlab | ||
| 4 | + | ||
| 3 | 5 | ||
| 4 | 6 | @pytest.fixture(scope="session") | |
| 5 | 7 | def test_dir(pytestconfig): | |
| 6 | 8 | return pytestconfig.rootdir / "tests" | |
| 7 | 9 | ||
| 8 | 10 | ||
| 11 | + @pytest.fixture(autouse=True) | ||
| 12 | + def mock_clean_config(monkeypatch): | ||
| 13 | + """Ensures user-defined environment variables do not interfere with tests.""" | ||
| 14 | + monkeypatch.delenv("PYTHON_GITLAB_CFG", raising=False) | ||
| 15 | + monkeypatch.delenv("GITLAB_PRIVATE_TOKEN", raising=False) | ||
| 16 | + monkeypatch.delenv("GITLAB_URL", raising=False) | ||
| 17 | + monkeypatch.delenv("CI_JOB_TOKEN", raising=False) | ||
| 18 | + monkeypatch.delenv("CI_SERVER_URL", raising=False) | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + @pytest.fixture(autouse=True) | ||
| 22 | + def default_files(monkeypatch): | ||
| 23 | + """Ensures user configuration files do not interfere with tests.""" | ||
| 24 | + monkeypatch.setattr(gitlab.config, "_DEFAULT_FILES", []) | ||
| 25 | + | ||
| 26 | + | ||
| 9 | 27 | @pytest.fixture | |
| 10 | 28 | def valid_gitlab_ci_yml(): | |
| 11 | 29 | return """--- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,6 @@ | |||
| 3 | 3 | import pytest | |
| 4 | 4 | import responses | |
| 5 | 5 | ||
| 6 | - from gitlab import config | ||
| 7 | 6 | from gitlab.const import DEFAULT_URL | |
| 8 | 7 | ||
| 9 | 8 | ||
@@ -37,10 +36,7 @@ def test_list_project_variables_with_path(gitlab_cli, project): | |||
| 37 | 36 | ||
| 38 | 37 | @pytest.mark.script_launch_mode("inprocess") | |
| 39 | 38 | @responses.activate | |
| 40 | - def test_list_project_variables_with_path_url_check( | ||
| 41 | - monkeypatch, script_runner, resp_get_project | ||
| 42 | - ): | ||
| 43 | - monkeypatch.setattr(config, "_DEFAULT_FILES", []) | ||
| 39 | + def test_list_project_variables_with_path_url_check(script_runner, resp_get_project): | ||
| 44 | 40 | resp_get_project_variables = copy.deepcopy(resp_get_project) | |
| 45 | 41 | resp_get_project_variables.update( | |
| 46 | 42 | url=f"{DEFAULT_URL}/api/v4/projects/project%2Fwith%2Fa%2Fnamespace/variables" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,6 +100,12 @@ | |||
| 100 | 100 | """ | |
| 101 | 101 | ||
| 102 | 102 | ||
| 103 | + @pytest.fixture(autouse=True) | ||
| 104 | + def default_files(monkeypatch): | ||
| 105 | + """Overrides mocked default files from conftest.py as we have our own mocks here.""" | ||
| 106 | + monkeypatch.setattr(gitlab.config, "_DEFAULT_FILES", config._DEFAULT_FILES) | ||
| 107 | + | ||
| 108 | + | ||
| 103 | 109 | def global_retry_transient_errors(value: bool) -> str: | |
| 104 | 110 | return f"""[global] | |
| 105 | 111 | default = one | |
@@ -129,24 +135,19 @@ def _mock_existent_file(path, *args, **kwargs): | |||
| 129 | 135 | return path | |
| 130 | 136 | ||
| 131 | 137 | ||
| 132 | - @pytest.fixture | ||
| 133 | - def mock_clean_env(monkeypatch): | ||
| 134 | - monkeypatch.delenv("PYTHON_GITLAB_CFG", raising=False) | ||
| 135 | - | ||
| 136 | - | ||
| 137 | 138 | def test_env_config_missing_file_raises(monkeypatch): | |
| 138 | 139 | monkeypatch.setenv("PYTHON_GITLAB_CFG", "/some/path") | |
| 139 | 140 | with pytest.raises(config.GitlabConfigMissingError): | |
| 140 | 141 | config._get_config_files() | |
| 141 | 142 | ||
| 142 | 143 | ||
| 143 | - def test_env_config_not_defined_does_not_raise(mock_clean_env, monkeypatch): | ||
| 144 | + def test_env_config_not_defined_does_not_raise(monkeypatch): | ||
| 144 | 145 | with monkeypatch.context() as m: | |
| 145 | 146 | m.setattr(config, "_DEFAULT_FILES", []) | |
| 146 | 147 | assert config._get_config_files() == [] | |
| 147 | 148 | ||
| 148 | 149 | ||
| 149 | - def test_default_config(mock_clean_env, monkeypatch): | ||
| 150 | + def test_default_config(monkeypatch): | ||
| 150 | 151 | with monkeypatch.context() as m: | |
| 151 | 152 | m.setattr(Path, "resolve", _mock_nonexistent_file) | |
| 152 | 153 | cp = config.GitlabConfigParser() | |
@@ -169,7 +170,7 @@ def test_default_config(mock_clean_env, monkeypatch): | |||
| 169 | 170 | ||
| 170 | 171 | ||
| 171 | 172 | @mock.patch("builtins.open") | |
| 172 | - def test_invalid_id(m_open, mock_clean_env, monkeypatch): | ||
| 173 | + def test_invalid_id(m_open, monkeypatch): | ||
| 173 | 174 | fd = io.StringIO(no_default_config) | |
| 174 | 175 | fd.close = mock.Mock(return_value=None) | |
| 175 | 176 | m_open.return_value = fd | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,6 @@ | |||
| 20 | 20 | import logging | |
| 21 | 21 | import pickle | |
| 22 | 22 | from http.client import HTTPConnection | |
| 23 | - from typing import List, Optional, Union | ||
| 24 | 23 | ||
| 25 | 24 | import pytest | |
| 26 | 25 | import responses | |
@@ -301,11 +300,7 @@ def test_gitlab_from_config(default_config): | |||
| 301 | 300 | gitlab.Gitlab.from_config("one", [config_path]) | |
| 302 | 301 | ||
| 303 | 302 | ||
| 304 | - def test_gitlab_from_config_without_files_raises(monkeypatch): | ||
| 305 | - def no_files(config_files: Optional[List[str]] = None) -> Union[str, List[str]]: | ||
| 306 | - return [] | ||
| 307 | - | ||
| 308 | - monkeypatch.setattr(gitlab.config, "_get_config_files", no_files) | ||
| 303 | + def test_gitlab_from_config_without_files_raises(): | ||
| 309 | 304 | with pytest.raises(GitlabConfigMissingError, match="non-existing"): | |
| 310 | 305 | gitlab.Gitlab.from_config("non-existing") | |
| 311 | 306 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments