Skip to content

Commit 93b2258

Browse files
authored
Fix config test: ignore all env vars in test environment (#10835)
* Remove unused other_settings param * Don't mutate original test param * Ignore all environment variables in the test env Except for WAREHOUSE_ENV
1 parent b4ab21a commit 93b2258

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

tests/unit/test_config.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13+
import os
14+
1315
from unittest import mock
1416

1517
import pretend
@@ -157,17 +159,17 @@ def test_maybe_set_compound(monkeypatch, environ, base, name, envvar, expected):
157159

158160

159161
@pytest.mark.parametrize(
160-
("settings", "environment", "other_settings"),
162+
("settings", "environment"),
161163
[
162-
(None, config.Environment.production, {}),
163-
({}, config.Environment.production, {}),
164-
({"my settings": "the settings value"}, config.Environment.production, {}),
165-
(None, config.Environment.development, {}),
166-
({}, config.Environment.development, {}),
167-
({"my settings": "the settings value"}, config.Environment.development, {}),
164+
(None, config.Environment.production),
165+
({}, config.Environment.production),
166+
({"my settings": "the settings value"}, config.Environment.production),
167+
(None, config.Environment.development),
168+
({}, config.Environment.development),
169+
({"my settings": "the settings value"}, config.Environment.development),
168170
],
169171
)
170-
def test_configure(monkeypatch, settings, environment, other_settings):
172+
def test_configure(monkeypatch, settings, environment):
171173
json_renderer_obj = pretend.stub()
172174
json_renderer_cls = pretend.call_recorder(lambda **kw: json_renderer_obj)
173175
monkeypatch.setattr(renderers, "JSON", json_renderer_cls)
@@ -176,8 +178,17 @@ def test_configure(monkeypatch, settings, environment, other_settings):
176178
xmlrpc_renderer_cls = pretend.call_recorder(lambda **kw: xmlrpc_renderer_obj)
177179
monkeypatch.setattr(config, "XMLRPCRenderer", xmlrpc_renderer_cls)
178180

179-
if environment == config.Environment.development:
180-
monkeypatch.setenv("WAREHOUSE_ENV", "development")
181+
# Ignore all environment variables in the test environment, except for WAREHOUSE_ENV
182+
monkeypatch.setattr(
183+
os,
184+
"environ",
185+
{
186+
"WAREHOUSE_ENV": {
187+
config.Environment.development: "development",
188+
config.Environment.production: "production",
189+
}[environment],
190+
},
191+
)
181192

182193
class FakeRegistry(dict):
183194
def __init__(self):
@@ -190,7 +201,7 @@ def __init__(self):
190201
"warehouse.xmlrpc.client.ratelimit_string": "3600 per hour",
191202
}
192203

193-
configurator_settings = other_settings.copy()
204+
configurator_settings = dict()
194205
configurator_obj = pretend.stub(
195206
registry=FakeRegistry(),
196207
set_root_factory=pretend.call_recorder(lambda rf: None),
@@ -225,7 +236,7 @@ def __init__(self):
225236
)
226237
monkeypatch.setattr(config, "transaction", transaction)
227238

228-
result = config.configure(settings=settings)
239+
result = config.configure(settings=settings.copy() if settings else None)
229240

230241
expected_settings = {
231242
"warehouse.env": environment,

0 commit comments

Comments
 (0)