@@ -845,9 +845,8 @@ def setUp(self):
845845 os .makedirs (t2_path )
846846
847847 for path in tmp1_path , tmp2_path , tmp3_path , tmp4_path :
848- f = open (path , "w" )
849- f .write ("I'm " + path + " and proud of it. Blame test_os.\n " )
850- f .close ()
848+ with open (path , "x" ) as f :
849+ f .write ("I'm " + path + " and proud of it. Blame test_os.\n " )
851850
852851 if support .can_symlink ():
853852 os .symlink (os .path .abspath (t2_path ), self .link_path )
@@ -1427,6 +1426,9 @@ def test_internal_execvpe_str(self):
14271426
14281427@unittest .skipUnless (sys .platform == "win32" , "Win32 specific tests" )
14291428class Win32ErrorTests (unittest .TestCase ):
1429+ def setUp (self ):
1430+ self .assertFalse (os .path .exists (support .TESTFN ))
1431+
14301432 def test_rename (self ):
14311433 self .assertRaises (OSError , os .rename , support .TESTFN , support .TESTFN + ".bak" )
14321434
@@ -1439,7 +1441,7 @@ def test_chdir(self):
14391441 def test_mkdir (self ):
14401442 self .addCleanup (support .unlink , support .TESTFN )
14411443
1442- with open (support .TESTFN , "w " ) as f :
1444+ with open (support .TESTFN , "x " ) as f :
14431445 self .assertRaises (OSError , os .mkdir , support .TESTFN )
14441446
14451447 def test_utime (self ):
@@ -1448,6 +1450,7 @@ def test_utime(self):
14481450 def test_chmod (self ):
14491451 self .assertRaises (OSError , os .chmod , support .TESTFN , 0 )
14501452
1453+
14511454class TestInvalidFD (unittest .TestCase ):
14521455 singles = ["fchdir" , "dup" , "fdopen" , "fdatasync" , "fstat" ,
14531456 "fstatvfs" , "fsync" , "tcgetpgrp" , "ttyname" ]
@@ -1559,8 +1562,7 @@ def tearDown(self):
15591562 os .unlink (file )
15601563
15611564 def _test_link (self , file1 , file2 ):
1562- with open (file1 , "w" ) as f1 :
1563- f1 .write ("test" )
1565+ create_file (file1 )
15641566
15651567 with bytes_filename_warn (False ):
15661568 os .link (file1 , file2 )
0 commit comments