Make sure we reset environment variables.
authorCory Benfield <lukasaoz@gmail.com>
Sun, 18 Nov 2012 12:31:55 +0000 (12:31 +0000)
committerCory Benfield <lukasaoz@gmail.com>
Sun, 18 Nov 2012 12:31:55 +0000 (12:31 +0000)
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

index 7febc570677a2bed5456a41abb10eedbfcc9ac1a..015cac633bdb4fd2f7d19680dd991a5a6d332705 100644 (file)
@@ -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()