]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109237: Fix test_site for non-ASCII working directory (#109238)
authorVictor Stinner <vstinner@python.org>
Sun, 10 Sep 2023 22:04:35 +0000 (00:04 +0200)
committerGitHub <noreply@github.com>
Sun, 10 Sep 2023 22:04:35 +0000 (22:04 +0000)
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.

Lib/test/test_site.py
Misc/NEWS.d/next/Tests/2023-09-10-22-32-20.gh-issue-109237.SvgKwD.rst [new file with mode: 0644]

index 20a96169e8be4eb5e09026e31b684578f15f4077..e8ec3b35881fec2bc2cc3b0b76536628d9031f75 100644 (file)
@@ -576,7 +576,7 @@ class _pthFileTests(unittest.TestCase):
                 _pth_file = os.path.splitext(exe_file)[0] + '._pth'
             else:
                 _pth_file = os.path.splitext(dll_file)[0] + '._pth'
-            with open(_pth_file, 'w') as f:
+            with open(_pth_file, 'w', encoding='utf8') as f:
                 for line in lines:
                     print(line, file=f)
             return exe_file
@@ -613,7 +613,7 @@ class _pthFileTests(unittest.TestCase):
             os.path.dirname(exe_file),
             pth_lines)
 
-        output = subprocess.check_output([exe_file, '-c',
+        output = subprocess.check_output([exe_file, '-X', 'utf8', '-c',
             'import sys; print("\\n".join(sys.path) if sys.flags.no_site else "")'
         ], encoding='utf-8', errors='surrogateescape')
         actual_sys_path = output.rstrip().split('\n')
diff --git a/Misc/NEWS.d/next/Tests/2023-09-10-22-32-20.gh-issue-109237.SvgKwD.rst b/Misc/NEWS.d/next/Tests/2023-09-10-22-32-20.gh-issue-109237.SvgKwD.rst
new file mode 100644 (file)
index 0000000..1d762bb
--- /dev/null
@@ -0,0 +1,4 @@
+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. Patch by
+Victor Stinner.