Use test.test_support.EnvironmentVarGuard where tests change environment vars.
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 792ad5d..2b46c46 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -149,13 +149,11 @@
         # _candidate_tempdir_list contains the expected directories
 
         # Make sure the interesting environment variables are all set.
-        added = []
-        try:
+        with test_support.EnvironmentVarGuard() as env:
             for envname in 'TMPDIR', 'TEMP', 'TMP':
                 dirname = os.getenv(envname)
                 if not dirname:
-                    os.environ[envname] = os.path.abspath(envname)
-                    added.append(envname)
+                    env.set(envname, os.path.abspath(envname))
 
             cand = tempfile._candidate_tempdir_list()
 
@@ -173,9 +171,6 @@
 
             # Not practical to try to verify the presence of OS-specific
             # paths in this list.
-        finally:
-            for p in added:
-                del os.environ[p]
 
 test_classes.append(test__candidate_tempdir_list)