@@ -3095,11 +3095,6 @@ def test_stat_inaccessible_file(self):
3095
3095
3096
3096
stat1 = os .stat (filename )
3097
3097
3098
- # Read permissions back. This will help diagnose in case of failure
3099
- out = subprocess .check_output ([ICACLS , filename ], stderr = subprocess .STDOUT )
3100
- if support .verbose :
3101
- print (out .decode ("oem" , "backslashreplace" ))
3102
-
3103
3098
try :
3104
3099
# Remove all permissions from the file
3105
3100
subprocess .check_output ([ICACLS , filename , "/inheritance:r" ],
@@ -3114,6 +3109,22 @@ def test_stat_inaccessible_file(self):
3114
3109
pass
3115
3110
self .skipTest ("Unable to create inaccessible file" )
3116
3111
3112
+ # We should now not be able to open the file. If we can, the test isn't
3113
+ # going to work. A few retries to try and catch slow updates
3114
+ try :
3115
+ for _ in range (5 ):
3116
+ with open (filename , "rb" ) as f :
3117
+ pass
3118
+ time .sleep (0.5 )
3119
+ except PermissionError :
3120
+ pass
3121
+ else :
3122
+ try :
3123
+ os .unlink (filename )
3124
+ except Exception :
3125
+ pass
3126
+ self .skipTest ("Still had access to inaccessible file" )
3127
+
3117
3128
def cleanup ():
3118
3129
# Give delete permission. We are the file owner, so we can do this
3119
3130
# even though we removed all permissions earlier.
@@ -3134,11 +3145,6 @@ def cleanup():
3134
3145
if support .verbose :
3135
3146
print (" without access:" , stat2 )
3136
3147
3137
- # Read permissions back. This will help diagnose in case of failure
3138
- out = subprocess .check_output ([ICACLS , filename ], stderr = subprocess .STDOUT )
3139
- if support .verbose :
3140
- print (out .decode ("oem" , "backslashreplace" ))
3141
-
3142
3148
# We cannot get st_dev/st_ino, so ensure those are 0 or else our test
3143
3149
# is not set up correctly
3144
3150
self .assertEqual (0 , stat2 .st_dev )
0 commit comments