Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fc55a2

Browse files
committed
test_platform: Save/restore os.environ on Windows
1 parent b161562 commit 0fc55a2

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/test/test_platform.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def test_architecture_via_symlink(self): # issue3762
1818
# On Windows, the EXE needs to know where pythonXY.dll is at so we have
1919
# to add the directory to the path.
2020
if sys.platform == "win32":
21+
def restore_environ(old_env):
22+
os.environ.clear()
23+
os.environ.update(old_env)
24+
25+
self.addCleanup(restore_environ, dict(os.environ))
26+
2127
os.environ["Path"] = "{};{}".format(
2228
os.path.dirname(sys.executable), os.environ["Path"])
2329

@@ -26,6 +32,7 @@ def get(python):
2632
'import platform; print(platform.architecture())']
2733
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
2834
return p.communicate()
35+
2936
real = os.path.realpath(sys.executable)
3037
link = os.path.abspath(support.TESTFN)
3138
os.symlink(real, link)

0 commit comments

Comments
 (0)