Skip to content

Commit cef4951

Browse files
[3.11] gh-109237: Fix test_site for non-ASCII working directory (GH-109238) (#109240)
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 b070d73 commit cef4951

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/test/test_site.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def _create_underpth_exe(self, lines, exe_pth=True):
577577
_pth_file = os.path.splitext(exe_file)[0] + '._pth'
578578
else:
579579
_pth_file = os.path.splitext(dll_file)[0] + '._pth'
580-
with open(_pth_file, 'w') as f:
580+
with open(_pth_file, 'w', encoding='utf8') as f:
581581
for line in lines:
582582
print(line, file=f)
583583
return exe_file
@@ -614,7 +614,7 @@ def test_underpth_basic(self):
614614
os.path.dirname(exe_file),
615615
pth_lines)
616616

617-
output = subprocess.check_output([exe_file, '-c',
617+
output = subprocess.check_output([exe_file, '-X', 'utf8', '-c',
618618
'import sys; print("\\n".join(sys.path) if sys.flags.no_site else "")'
619619
], encoding='utf-8', errors='surrogateescape')
620620
actual_sys_path = output.rstrip().split('\n')
Lines changed: 4 additions & 0 deletions
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)