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 ():
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 :
@@ -581,18 +546,18 @@ def display_header():
581
546
sanitizers .append ("memory" )
582
547
if ubsan :
583
548
sanitizers .append ("undefined behavior" )
584
- if not sanitizers :
585
- return
586
-
587
- print ( f"== sanitizers: { ', ' . join ( sanitizers ) } " )
588
- for sanitizer , env_var in (
589
- ( asan , "ASAN_OPTIONS " ),
590
- ( msan , "MSAN_OPTIONS" ),
591
- ( ubsan , "UBSAN_OPTIONS" ),
592
- ) :
593
- options = os . environ . get ( env_var )
594
- if sanitizer and options is not None :
595
- print (f"== { env_var } = { options !r } " )
549
+ if sanitizers :
550
+ print ( f"== sanitizers: { ', ' . join ( sanitizers ) } " )
551
+ for sanitizer , env_var in (
552
+ ( asan , "ASAN_OPTIONS" ),
553
+ ( msan , "MSAN_OPTIONS" ),
554
+ ( ubsan , "UBSAN_OPTIONS " ),
555
+ ):
556
+ options = os . environ . get ( env_var )
557
+ if sanitizer and options is not None :
558
+ print ( f"== { env_var } = { options !r } " )
559
+
560
+ print (flush = True )
596
561
597
562
598
563
def cleanup_temp_dir (tmp_dir : StrPath ):
0 commit comments