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

Commit8d4f13b

Browse files
nejchJohnVillalovos
authored andcommitted
test: always ensure clean config environment
1 parent4b798fc commit8d4f13b

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

‎tests/conftest.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
importpytest
22

3+
importgitlab
4+
35

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

810

11+
@pytest.fixture(autouse=True)
12+
defmock_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+
defdefault_files(monkeypatch):
23+
"""Ensures user configuration files do not interfere with tests."""
24+
monkeypatch.setattr(gitlab.config,"_DEFAULT_FILES", [])
25+
26+
927
@pytest.fixture
1028
defvalid_gitlab_ci_yml():
1129
return"""---

‎tests/functional/cli/test_cli_variables.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
importpytest
44
importresponses
55

6-
fromgitlabimportconfig
76
fromgitlab.constimportDEFAULT_URL
87

98

@@ -37,10 +36,7 @@ def test_list_project_variables_with_path(gitlab_cli, project):
3736

3837
@pytest.mark.script_launch_mode("inprocess")
3938
@responses.activate
40-
deftest_list_project_variables_with_path_url_check(
41-
monkeypatch,script_runner,resp_get_project
42-
):
43-
monkeypatch.setattr(config,"_DEFAULT_FILES", [])
39+
deftest_list_project_variables_with_path_url_check(script_runner,resp_get_project):
4440
resp_get_project_variables=copy.deepcopy(resp_get_project)
4541
resp_get_project_variables.update(
4642
url=f"{DEFAULT_URL}/api/v4/projects/project%2Fwith%2Fa%2Fnamespace/variables"

‎tests/unit/test_config.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@
100100
"""
101101

102102

103+
@pytest.fixture(autouse=True)
104+
defdefault_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+
103109
defglobal_retry_transient_errors(value:bool)->str:
104110
returnf"""[global]
105111
default = one
@@ -129,24 +135,19 @@ def _mock_existent_file(path, *args, **kwargs):
129135
returnpath
130136

131137

132-
@pytest.fixture
133-
defmock_clean_env(monkeypatch):
134-
monkeypatch.delenv("PYTHON_GITLAB_CFG",raising=False)
135-
136-
137138
deftest_env_config_missing_file_raises(monkeypatch):
138139
monkeypatch.setenv("PYTHON_GITLAB_CFG","/some/path")
139140
withpytest.raises(config.GitlabConfigMissingError):
140141
config._get_config_files()
141142

142143

143-
deftest_env_config_not_defined_does_not_raise(mock_clean_env,monkeypatch):
144+
deftest_env_config_not_defined_does_not_raise(monkeypatch):
144145
withmonkeypatch.context()asm:
145146
m.setattr(config,"_DEFAULT_FILES", [])
146147
assertconfig._get_config_files()== []
147148

148149

149-
deftest_default_config(mock_clean_env,monkeypatch):
150+
deftest_default_config(monkeypatch):
150151
withmonkeypatch.context()asm:
151152
m.setattr(Path,"resolve",_mock_nonexistent_file)
152153
cp=config.GitlabConfigParser()
@@ -169,7 +170,7 @@ def test_default_config(mock_clean_env, monkeypatch):
169170

170171

171172
@mock.patch("builtins.open")
172-
deftest_invalid_id(m_open,mock_clean_env,monkeypatch):
173+
deftest_invalid_id(m_open,monkeypatch):
173174
fd=io.StringIO(no_default_config)
174175
fd.close=mock.Mock(return_value=None)
175176
m_open.return_value=fd

‎tests/unit/test_gitlab.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
importlogging
2121
importpickle
2222
fromhttp.clientimportHTTPConnection
23-
fromtypingimportList,Optional,Union
2423

2524
importpytest
2625
importresponses
@@ -301,11 +300,7 @@ def test_gitlab_from_config(default_config):
301300
gitlab.Gitlab.from_config("one", [config_path])
302301

303302

304-
deftest_gitlab_from_config_without_files_raises(monkeypatch):
305-
defno_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+
deftest_gitlab_from_config_without_files_raises():
309304
withpytest.raises(GitlabConfigMissingError,match="non-existing"):
310305
gitlab.Gitlab.from_config("non-existing")
311306

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp