Skip to content

Commit 85965ca

Browse files
committed
Refactor test for proxy conflict in get_client method
Signed-off-by: Shahaf Bahar <[email protected]>
1 parent de9c6a8 commit 85965ca

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/test_resources.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
import yaml
33
import kubernetes
4-
import os
54
from testcontainers.k3s import K3SContainer
65

76
from ocp_resources.exceptions import ResourceTeardownError
@@ -106,14 +105,16 @@ def test_resource_context_manager_exit(self, client):
106105
with TestSecretExit(name="test-context-manager-exit", namespace="default", client=client):
107106
pass
108107

109-
def test_proxy_conflict_raises_value_error(self):
110-
os.environ["OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY"] = "1"
111-
os.environ["HTTPS_PROXY"] = "http://env-proxy.com"
108+
def test_proxy_conflict_raises_value_error(self, monkeypatch):
109+
monkeypatch.setenv(name="OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY", value="1")
110+
monkeypatch.setenv(name="HTTPS_PROXY", value="http://env-proxy.com")
111+
112112
client_configuration = kubernetes.client.Configuration()
113113
client_configuration.proxy = "http://not-env-proxy.com"
114-
with pytest.raises(
115-
ValueError,
116-
match="Conflicting proxy settings: client_configuration.proxy=http://not-env-proxy.com, "
117-
"but the environment variable 'OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY' defines proxy as http://env-proxy.com.",
118-
):
114+
115+
with pytest.raises(ValueError) as exc_info:
119116
get_client(client_configuration=client_configuration)
117+
118+
assert "Conflicting proxy settings" in str(exc_info.value)
119+
assert "http://not-env-proxy.com" in str(exc_info.value)
120+
assert "http://env-proxy.com" in str(exc_info.value)

0 commit comments

Comments
 (0)