- Notifications
You must be signed in to change notification settings - Fork675
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletionstests/conftest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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) | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| @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"""--- | ||
6 changes: 1 addition & 5 deletionstests/functional/cli/test_cli_variables.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletionstests/unit/test_config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| def global_retry_transient_errors(value: bool) -> str: | ||
| return f"""[global] | ||
| default = one | ||
| @@ -129,24 +135,19 @@ def _mock_existent_file(path, *args, **kwargs): | ||
| return path | ||
| 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(monkeypatch): | ||
| with monkeypatch.context() as m: | ||
| m.setattr(config, "_DEFAULT_FILES", []) | ||
| assert config._get_config_files() == [] | ||
| def test_default_config(monkeypatch): | ||
| with monkeypatch.context() as m: | ||
| m.setattr(Path, "resolve", _mock_nonexistent_file) | ||
| cp = config.GitlabConfigParser() | ||
| @@ -169,7 +170,7 @@ def test_default_config(mock_clean_env, monkeypatch): | ||
| @mock.patch("builtins.open") | ||
| 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 | ||
7 changes: 1 addition & 6 deletionstests/unit/test_gitlab.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.