From c02520ed99d5aead74d70bcae70d3d1fa6424012 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Sun, 18 Nov 2012 12:31:55 +0000 Subject: [PATCH] Make sure we reset environment variables. Turns out nose runs all the tests in one process, so changing the os.environ dictionary makes everything go horribly wrong. --- tests/test_utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 7febc57..015cac6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -78,6 +78,17 @@ class UtilityTests(unittest.TestCase): '''This test confirms that the no_proxy environment setting is respected by get_environ_proxies().''' + # Store the current environment settings. + try: + old_http_proxy = os.environ['http_proxy'] + except KeyError: + old_http_proxy = None + + try: + old_no_proxy = os.environ['no_proxy'] + except KeyError: + old_no_proxy = None + # Set up some example environment settings. os.environ['http_proxy'] = 'http://www.example.com/' os.environ['no_proxy'] = r'localhost,.0.0.1:8080' @@ -96,6 +107,16 @@ class UtilityTests(unittest.TestCase): self.assertEqual(proxy_yes, get_environ_proxies('http://127.0.0.1:8081/')) + # Return the settings to what they were. + if old_http_proxy: + os.environ['http_proxy'] = old_http_proxy + else: + del os.environ['http_proxy'] + + if old_no_proxy: + os.environ['no_proxy'] = old_no_proxy + else: + del os.environ['no_proxy'] if __name__ == '__main__': unittest.main() -- 2.34.1