@@ -169,7 +169,7 @@ def __enter__(self):
169169
170170 if self .synchronize and self .std :
171171 # Cause Python's stdout to point to our new file
172- self .target_file = os .fdopen (self .fd , 'a' , closefd = False )
172+ self .target_file = os .fdopen (self .fd , "w" , closefd = False )
173173 setattr (sys , self .std , self .target_file )
174174
175175 return self
@@ -349,7 +349,7 @@ def _enter_impl(self):
349349 log_stream = self ._enter_context (
350350 os .fdopen (
351351 self ._enter_context (_fd_closer (os .dup (old_fd [1 ] or 2 ))),
352- mode = "a " ,
352+ mode = "w " ,
353353 closefd = False ,
354354 )
355355 )
@@ -358,7 +358,7 @@ def _enter_impl(self):
358358 self ._enter_context (LoggingIntercept (log_stream , logger = logger , level = None ))
359359
360360 if isinstance (self .output , str ):
361- self .output_stream = self ._enter_context (open (self .output , 'a' ))
361+ self .output_stream = self ._enter_context (open (self .output , "a" ))
362362 elif self .output is None :
363363 self .output_stream = io .StringIO ()
364364 else :
@@ -415,7 +415,7 @@ def _enter_impl(self):
415415 _fd_closer (os .dup (fd_redirect [fd ].original_fd )),
416416 prior_to = self .tee ,
417417 ),
418- mode = "a " ,
418+ mode = "w " ,
419419 closefd = False ,
420420 ),
421421 prior_to = self .tee ,
@@ -673,7 +673,7 @@ def STDERR(self):
673673 self ._stderr = self .open (buffering = b )
674674 return self ._stderr
675675
676- def open (self , mode = 'a' , buffering = - 1 , encoding = None , newline = None ):
676+ def open (self , mode = "w" , buffering = - 1 , encoding = None , newline = None ):
677677 if encoding is None :
678678 encoding = self .encoding
679679 handle = _StreamHandle (mode , buffering , encoding , newline )
0 commit comments