mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
test_platform: Save/restore os.environ on Windows
This commit is contained in:
parent
b161562f72
commit
0fc55a234f
1 changed files with 7 additions and 0 deletions
|
@ -18,6 +18,12 @@ class PlatformTest(unittest.TestCase):
|
||||||
# On Windows, the EXE needs to know where pythonXY.dll is at so we have
|
# On Windows, the EXE needs to know where pythonXY.dll is at so we have
|
||||||
# to add the directory to the path.
|
# to add the directory to the path.
|
||||||
if sys.platform == "win32":
|
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.environ["Path"] = "{};{}".format(
|
||||||
os.path.dirname(sys.executable), os.environ["Path"])
|
os.path.dirname(sys.executable), os.environ["Path"])
|
||||||
|
|
||||||
|
@ -26,6 +32,7 @@ class PlatformTest(unittest.TestCase):
|
||||||
'import platform; print(platform.architecture())']
|
'import platform; print(platform.architecture())']
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
return p.communicate()
|
return p.communicate()
|
||||||
|
|
||||||
real = os.path.realpath(sys.executable)
|
real = os.path.realpath(sys.executable)
|
||||||
link = os.path.abspath(support.TESTFN)
|
link = os.path.abspath(support.TESTFN)
|
||||||
os.symlink(real, link)
|
os.symlink(real, link)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue