Use test.test_support.EnvironmentVarGuard where tests change environment vars.
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index e6f750a..b7fbd50 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -345,10 +345,9 @@
self.assert_(isinstance(posixpath.expanduser("~root/"), basestring))
self.assert_(isinstance(posixpath.expanduser("~foo/"), basestring))
- orig_home = os.environ['HOME']
- os.environ['HOME'] = '/'
- self.assertEqual(posixpath.expanduser("~"), "/")
- os.environ['HOME'] = orig_home
+ with test_support.EnvironmentVarGuard() as env:
+ env.set('HOME', '/')
+ self.assertEqual(posixpath.expanduser("~"), "/")
self.assertRaises(TypeError, posixpath.expanduser)