Skip to content

Commit e07a146

Browse files
committed
tests: make urlllib3 transport tests more robust against local env
When mocking os.environ pass clear=True to avoid getting host configurations. Fix #1968
1 parent 460f141 commit e07a146

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/transports/test_urllib3.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,38 +115,38 @@ def test_generic_error(mock_urlopen, elasticapm_client):
115115

116116

117117
def test_http_proxy_environment_variable(elasticapm_client):
118-
with mock.patch.dict("os.environ", {"HTTP_PROXY": "http://example.com"}):
118+
with mock.patch.dict("os.environ", {"HTTP_PROXY": "http://example.com"}, clear=True):
119119
transport = Transport("http://localhost:9999", client=elasticapm_client)
120120
assert isinstance(transport.http, urllib3.ProxyManager)
121121

122122

123123
def test_https_proxy_environment_variable(elasticapm_client):
124-
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com"}):
124+
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com",}, clear=True):
125125
transport = Transport("http://localhost:9999", client=elasticapm_client)
126126
assert isinstance(transport.http, urllib3.poolmanager.ProxyManager)
127127

128128

129129
def test_https_proxy_environment_variable_is_preferred(elasticapm_client):
130-
with mock.patch.dict("os.environ", {"https_proxy": "https://example.com", "HTTP_PROXY": "http://example.com"}):
130+
with mock.patch.dict("os.environ", {"https_proxy": "https://example.com", "HTTP_PROXY": "http://example.com"}, clear=True):
131131
transport = Transport("http://localhost:9999", client=elasticapm_client)
132132
assert isinstance(transport.http, urllib3.poolmanager.ProxyManager)
133133
assert transport.http.proxy.scheme == "https"
134134

135135

136136
def test_no_proxy_star(elasticapm_client):
137-
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}):
137+
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}, clear=True):
138138
transport = Transport("http://localhost:9999", client=elasticapm_client)
139139
assert not isinstance(transport.http, urllib3.poolmanager.ProxyManager)
140140

141141

142142
def test_no_proxy_host(elasticapm_client):
143-
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "localhost"}):
143+
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "localhost"}, clear=True):
144144
transport = Transport("http://localhost:9999", client=elasticapm_client)
145145
assert not isinstance(transport.http, urllib3.poolmanager.ProxyManager)
146146

147147

148148
def test_no_proxy_all(elasticapm_client):
149-
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}):
149+
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}, clear=True):
150150
transport = Transport("http://localhost:9999", client=elasticapm_client)
151151
assert not isinstance(transport.http, urllib3.poolmanager.ProxyManager)
152152

0 commit comments

Comments
 (0)