Skip to content

Commit b361381

Browse files
[3.12] gh-109237: Fix test_site for non-ASCII working directory (GH-109238) (#109239)
gh-109237: Fix test_site for non-ASCII working directory (GH-109238) Fix test_site.test_underpth_basic() when the working directory contains at least one non-ASCII character: encode the "._pth" file to UTF-8 and enable the UTF-8 Mode to use UTF-8 for the child process stdout. (cherry picked from commit cbb3a6f) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent bcd5907 commit b361381

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/test/test_site.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def _create_underpth_exe(self, lines, exe_pth=True):
576576
_pth_file = os.path.splitext(exe_file)[0] + '._pth'
577577
else:
578578
_pth_file = os.path.splitext(dll_file)[0] + '._pth'
579-
with open(_pth_file, 'w') as f:
579+
with open(_pth_file, 'w', encoding='utf8') as f:
580580
for line in lines:
581581
print(line, file=f)
582582
return exe_file
@@ -613,7 +613,7 @@ def test_underpth_basic(self):
613613
os.path.dirname(exe_file),
614614
pth_lines)
615615

616-
output = subprocess.check_output([exe_file, '-c',
616+
output = subprocess.check_output([exe_file, '-X', 'utf8', '-c',
617617
'import sys; print("\\n".join(sys.path) if sys.flags.no_site else "")'
618618
], encoding='utf-8', errors='surrogateescape')
619619
actual_sys_path = output.rstrip().split('\n')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix ``test_site.test_underpth_basic()`` when the working directory contains
2+
at least one non-ASCII character: encode the ``._pth`` file to UTF-8 and
3+
enable the UTF-8 Mode to use UTF-8 for the child process stdout. Patch by
4+
Victor Stinner.

0 commit comments

Comments
 (0)