From 3090115b1bc728f8294976561aafd6078360b1d5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 11 Sep 2023 00:04:35 +0200 Subject: [PATCH] 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 cbb3a6f8ada3d133c3ab9f9465b65067fce5bb42) Co-authored-by: Victor Stinner --- Lib/test/test_site.py | 4 ++-- .../next/Tests/2023-09-10-22-32-20.gh-issue-109237.SvgKwD.rst | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2023-09-10-22-32-20.gh-issue-109237.SvgKwD.rst diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 12a2b73a3fe2fb..613e946ba71ba2 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -577,7 +577,7 @@ def _create_underpth_exe(self, lines, exe_pth=True): _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 @@ -614,7 +614,7 @@ def test_underpth_basic(self): 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 index 00000000000000..1d762bbe1d2592 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-09-10-22-32-20.gh-issue-109237.SvgKwD.rst @@ -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.