1
- import atexit
2
1
import contextlib
3
2
import faulthandler
4
3
import locale
@@ -495,32 +494,6 @@ def normalize_test_name(test_full_name, *, is_error=False):
495
494
return short_name
496
495
497
496
498
- def replace_stdout ():
499
- """Set stdout encoder error handler to backslashreplace (as stderr error
500
- handler) to avoid UnicodeEncodeError when printing a traceback"""
501
- stdout = sys .stdout
502
- try :
503
- fd = stdout .fileno ()
504
- except ValueError :
505
- # On IDLE, sys.stdout has no file descriptor and is not a TextIOWrapper
506
- # object. Leaving sys.stdout unchanged.
507
- #
508
- # Catch ValueError to catch io.UnsupportedOperation on TextIOBase
509
- # and ValueError on a closed stream.
510
- return
511
-
512
- sys .stdout = open (fd , 'w' ,
513
- encoding = stdout .encoding ,
514
- errors = "backslashreplace" ,
515
- closefd = False ,
516
- newline = '\n ' )
517
-
518
- def restore_stdout ():
519
- sys .stdout .close ()
520
- sys .stdout = stdout
521
- atexit .register (restore_stdout )
522
-
523
-
524
497
def adjust_rlimit_nofile ():
525
498
"""
526
499
On macOS the default fd limit (RLIMIT_NOFILE) is sometimes too low (256)
@@ -548,20 +521,12 @@ def adjust_rlimit_nofile():
548
521
549
522
550
523
def display_header (use_resources : tuple [str , ...]):
551
- encoding = sys .stdout .encoding
552
-
553
524
# Print basic platform information
554
525
print ("==" , platform .python_implementation (), * sys .version .split ())
555
526
print ("==" , platform .platform (aliased = True ),
556
527
"%s-endian" % sys .byteorder )
557
528
print ("== Python build:" , ' ' .join (get_build_info ()))
558
-
559
- cwd = os .getcwd ()
560
- # gh-109508: support.os_helper.FS_NONASCII, used by get_work_dir(), cannot
561
- # be encoded to the filesystem encoding on purpose, escape non-encodable
562
- # characters with backslashreplace error handler.
563
- formatted_cwd = cwd .encode (encoding , "backslashreplace" ).decode (encoding )
564
- print ("== cwd:" , formatted_cwd )
529
+ print ("== cwd:" , os .getcwd ())
565
530
566
531
cpu_count = os .cpu_count ()
567
532
if cpu_count :
@@ -588,18 +553,18 @@ def display_header(use_resources: tuple[str, ...]):
588
553
sanitizers .append ("memory" )
589
554
if ubsan :
590
555
sanitizers .append ("undefined behavior" )
591
- if not sanitizers :
592
- return
593
-
594
- print ( f"== sanitizers: { ', ' . join ( sanitizers ) } " )
595
- for sanitizer , env_var in (
596
- ( asan , "ASAN_OPTIONS " ),
597
- ( msan , "MSAN_OPTIONS" ),
598
- ( ubsan , "UBSAN_OPTIONS" ),
599
- ) :
600
- options = os . environ . get ( env_var )
601
- if sanitizer and options is not None :
602
- print (f"== { env_var } = { options !r } " )
556
+ if sanitizers :
557
+ print ( f"== sanitizers: { ', ' . join ( sanitizers ) } " )
558
+ for sanitizer , env_var in (
559
+ ( asan , "ASAN_OPTIONS" ),
560
+ ( msan , "MSAN_OPTIONS" ),
561
+ ( ubsan , "UBSAN_OPTIONS " ),
562
+ ):
563
+ options = os . environ . get ( env_var )
564
+ if sanitizer and options is not None :
565
+ print ( f"== { env_var } = { options !r } " )
566
+
567
+ print (flush = True )
603
568
604
569
605
570
def cleanup_temp_dir (tmp_dir : StrPath ):
0 commit comments