aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/libregrtest/utils.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-26 21:34:50 +0200
committerGitHub <noreply@github.com>2023-09-26 21:34:50 +0200
commitb1e4f6e83e8916005caa3f751f25fb58cccbf812 (patch)
tree87131de209599f2cd2c36165b26744cf9bf19134 /Lib/test/libregrtest/utils.py
parentae1d99c2ed9d44b2554129f3a85b97a31119bccc (diff)
downloadcpython-b1e4f6e83e8916005caa3f751f25fb58cccbf812.tar.gz
cpython-b1e4f6e83e8916005caa3f751f25fb58cccbf812.zip
gh-109276, gh-109508: Fix libregrtest stdout (#109903)
Remove replace_stdout(): call sys.stdout.reconfigure() instead of set the error handler to backslashreplace. display_header() logs an empty line and flush stdout. Remove encoding workaround in display_header() since stdout error handler is now set to backslashreplace earlier.
Diffstat (limited to 'Lib/test/libregrtest/utils.py')
-rw-r--r--Lib/test/libregrtest/utils.py61
1 files changed, 13 insertions, 48 deletions
diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py
index f3f0eb53b32..acf35723a1a 100644
--- a/Lib/test/libregrtest/utils.py
+++ b/Lib/test/libregrtest/utils.py
@@ -1,4 +1,3 @@
-import atexit
import contextlib
import faulthandler
import locale
@@ -495,32 +494,6 @@ def normalize_test_name(test_full_name, *, is_error=False):
return short_name
-def replace_stdout():
- """Set stdout encoder error handler to backslashreplace (as stderr error
- handler) to avoid UnicodeEncodeError when printing a traceback"""
- stdout = sys.stdout
- try:
- fd = stdout.fileno()
- except ValueError:
- # On IDLE, sys.stdout has no file descriptor and is not a TextIOWrapper
- # object. Leaving sys.stdout unchanged.
- #
- # Catch ValueError to catch io.UnsupportedOperation on TextIOBase
- # and ValueError on a closed stream.
- return
-
- sys.stdout = open(fd, 'w',
- encoding=stdout.encoding,
- errors="backslashreplace",
- closefd=False,
- newline='\n')
-
- def restore_stdout():
- sys.stdout.close()
- sys.stdout = stdout
- atexit.register(restore_stdout)
-
-
def adjust_rlimit_nofile():
"""
On macOS the default fd limit (RLIMIT_NOFILE) is sometimes too low (256)
@@ -548,20 +521,12 @@ def adjust_rlimit_nofile():
def display_header(use_resources: tuple[str, ...]):
- 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()))
-
- 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)
+ print("== cwd:", os.getcwd())
cpu_count = os.cpu_count()
if cpu_count:
@@ -588,18 +553,18 @@ def display_header(use_resources: tuple[str, ...]):
sanitizers.append("memory")
if ubsan:
sanitizers.append("undefined behavior")
- if not sanitizers:
- return
-
- print(f"== sanitizers: {', '.join(sanitizers)}")
- for sanitizer, env_var in (
- (asan, "ASAN_OPTIONS"),
- (msan, "MSAN_OPTIONS"),
- (ubsan, "UBSAN_OPTIONS"),
- ):
- options= os.environ.get(env_var)
- if sanitizer and options is not None:
- print(f"== {env_var}={options!r}")
+ if sanitizers:
+ print(f"== sanitizers: {', '.join(sanitizers)}")
+ for sanitizer, env_var in (
+ (asan, "ASAN_OPTIONS"),
+ (msan, "MSAN_OPTIONS"),
+ (ubsan, "UBSAN_OPTIONS"),
+ ):
+ options= os.environ.get(env_var)
+ if sanitizer and options is not None:
+ print(f"== {env_var}={options!r}")
+
+ print(flush=True)
def cleanup_temp_dir(tmp_dir: StrPath):