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

Skip to content

Commit ce2d24d

Browse files
author
Victor Stinner
committed
Fix test_undecodable_env of test_subproces for non-ASCII directory
This test was introduced by r80421 (issue #8391). The fix: copy the environment variables instead of starting Python in an empty environement. In an empty environment, the locale is C and Python uses ASCII for the default file system encoding. The non-ASCII directory will be encoded using surrogates, but Python3 is unable to load a module or package with a filename using surrogates. See issue #8242 for more information about running Python3 with a non-ascii directory in an empty environement.
1 parent 13bb71c commit ce2d24d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,19 +807,23 @@ def test_undecodable_env(self):
807807

808808
# test str with surrogates
809809
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
810+
env = os.environ.copy()
811+
env[key] = value
810812
stdout = subprocess.check_output(
811813
[sys.executable, "-c", script],
812-
env={key: value})
814+
env=env)
813815
stdout = stdout.rstrip(b'\n\r')
814816
self.assertEquals(stdout, value_repr)
815817

816818
# test bytes
817819
key = key.encode("ascii", "surrogateescape")
818820
value = value.encode("ascii", "surrogateescape")
819821
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
822+
env = os.environ.copy()
823+
env[key] = value
820824
stdout = subprocess.check_output(
821825
[sys.executable, "-c", script],
822-
env={key: value})
826+
env=env)
823827
stdout = stdout.rstrip(b'\n\r')
824828
self.assertEquals(stdout, value_repr)
825829

0 commit comments

Comments
 (0)