From: Victor Stinner Date: Mon, 18 Sep 2023 14:45:48 +0000 (+0200) Subject: gh-109508: Fix libregrtest formatting of getcwd() (#109537) X-Git-Tag: v3.13.0a1~402 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef659b96169888e52b6ff03ce28fffaaa8f76818;p=thirdparty%2FPython%2Fcpython.git gh-109508: Fix libregrtest formatting of getcwd() (#109537) --- diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 2f3bc3c6019c..7675fbe16a21 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -556,12 +556,21 @@ def adjust_rlimit_nofile(): def display_header(): + encoding = sys.stdout.encoding + # Print basic platform information print("==", platform.python_implementation(), *sys.version.split()) print("==", platform.platform(aliased=True), "%s-endian" % sys.byteorder) print("== Python build:", ' '.join(get_build_info())) - print("== cwd:", os.getcwd()) + + cwd = os.getcwd() + # gh-109508: support.os_helper.FS_NONASCII, used by get_work_dir(), cannot + # be encoded to the filesystem encoding on purpose, escape non-encodable + # characters with backslashreplace error handler. + formatted_cwd = cwd.encode(encoding, "backslashreplace").decode(encoding) + print("== cwd:", formatted_cwd) + cpu_count = os.cpu_count() if cpu_count: print("== CPU count:", cpu_count)