From 59980b12198201e6685f4ce86dcfd25ec146074f Mon Sep 17 00:00:00 2001 From: mprahl Date: Mon, 6 Jan 2020 16:45:04 -0500 Subject: [PATCH] Use patch.dict instead of modifying the environment variable in test_standalone_metrics_server --- tests/test_common/test_monitor.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_common/test_monitor.py b/tests/test_common/test_monitor.py index 0cc651ac..bcd21d7a 100644 --- a/tests/test_common/test_monitor.py +++ b/tests/test_common/test_monitor.py @@ -38,15 +38,15 @@ def test_standalone_metrics_server_disabled_by_default(): def test_standalone_metrics_server(): - os.environ["MONITOR_STANDALONE_METRICS_SERVER_ENABLE"] = "true" - reload_module(module_build_service.common.monitor) + with mock.patch.dict(os.environ, {"MONITOR_STANDALONE_METRICS_SERVER_ENABLE": "true"}): + reload_module(module_build_service.common.monitor) - r = requests.get("http://127.0.0.1:10040/metrics") - count = len([ - l for l in r.text.splitlines() - if (l.startswith("# TYPE") and "_created " not in l) - ]) - assert count == num_of_metrics + r = requests.get("http://127.0.0.1:10040/metrics") + count = len([ + l for l in r.text.splitlines() + if (l.startswith("# TYPE") and "_created " not in l) + ]) + assert count == num_of_metrics @mock.patch("module_build_service.common.monitor.builder_failed_counter.labels")