[Python-checkins] cpython: test_platform: Save/restore os.environ on Windows

victor.stinner python-checkins at python.org
Sat Sep 10 06:25:38 EDT 2016


https://hg.python.org/cpython/rev/3ded89cdea11
changeset:   103566:3ded89cdea11
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sat Sep 10 06:24:47 2016 -0400
summary:
  test_platform: Save/restore os.environ on Windows

files:
  Lib/test/test_platform.py |  7 +++++++
  1 files changed, 7 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -18,6 +18,12 @@
         # On Windows, the EXE needs to know where pythonXY.dll is at so we have
         # to add the directory to the path.
         if sys.platform == "win32":
+            def restore_environ(old_env):
+                os.environ.clear()
+                os.environ.update(old_env)
+
+            self.addCleanup(restore_environ, dict(os.environ))
+
             os.environ["Path"] = "{};{}".format(
                 os.path.dirname(sys.executable), os.environ["Path"])
 
@@ -26,6 +32,7 @@
                 'import platform; print(platform.architecture())']
             p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
             return p.communicate()
+
         real = os.path.realpath(sys.executable)
         link = os.path.abspath(support.TESTFN)
         os.symlink(real, link)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list