@@ -337,30 +337,22 @@ def test_osx_android_utf8(self):
337337        self .assertEqual (p .returncode , 0 )
338338
339339    def  test_non_interactive_output_buffering (self ):
340-         PYTHONUNBUFFERED  =  "PYTHONUNBUFFERED" 
341-         python_unbuffered_value  =  os .environ .get (PYTHONUNBUFFERED , "0" )
342-         python_unbuffered_on  =  python_unbuffered_value  !=  "0" 
343-         if  python_unbuffered_on :
340+         with  os_helper .EnvironmentVarGuard () as  environ :
344341            # we expect buffered stdio 
345-             os .environ [PYTHONUNBUFFERED ] =  "0" 
346- 
347-         code  =  textwrap .dedent (""" 
348-             import sys 
349-             out = sys.stdout 
350-             print(out.isatty(), out.write_through, out.line_buffering) 
351-             err = sys.stderr 
352-             print(err.isatty(), err.write_through, err.line_buffering) 
353-         """ )
354-         args  =  [sys .executable , '-c' , code ]
355-         proc  =  subprocess .run (args , stdout = subprocess .PIPE ,
356-                               stderr = subprocess .PIPE , text = True , check = True )
357-         self .assertEqual (proc .stdout ,
358-                          'False False False\n ' 
359-                          'False False True\n ' )
360- 
361-         if  python_unbuffered_on :
362-             # restore original value 
363-             os .environ [PYTHONUNBUFFERED ] =  python_unbuffered_value 
342+             environ ["PYTHONUNBUFFERED" ] =  "0" 
343+             code  =  textwrap .dedent (""" 
344+                 import sys 
345+                 out = sys.stdout 
346+                 print(out.isatty(), out.write_through, out.line_buffering) 
347+                 err = sys.stderr 
348+                 print(err.isatty(), err.write_through, err.line_buffering) 
349+             """ )
350+             args  =  [sys .executable , '-c' , code ]
351+             proc  =  subprocess .run (args , stdout = subprocess .PIPE ,
352+                                 stderr = subprocess .PIPE , text = True , check = True )
353+             self .assertEqual (proc .stdout ,
354+                             'False False False\n ' 
355+                             'False False True\n ' )
364356
365357    def  test_unbuffered_output (self ):
366358        # Test expected operation of the '-u' switch 
0 commit comments