Skip to content

Commit 6d0eac5

Browse files
committed
Alternate idea
1 parent e6623e6 commit 6d0eac5

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

Lib/test/test_os.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,11 +3095,6 @@ def test_stat_inaccessible_file(self):
30953095

30963096
stat1 = os.stat(filename)
30973097

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-
31033098
try:
31043099
# Remove all permissions from the file
31053100
subprocess.check_output([ICACLS, filename, "/inheritance:r"],
@@ -3114,6 +3109,22 @@ def test_stat_inaccessible_file(self):
31143109
pass
31153110
self.skipTest("Unable to create inaccessible file")
31163111

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+
31173128
def cleanup():
31183129
# Give delete permission. We are the file owner, so we can do this
31193130
# even though we removed all permissions earlier.
@@ -3134,11 +3145,6 @@ def cleanup():
31343145
if support.verbose:
31353146
print(" without access:", stat2)
31363147

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-
31423148
# We cannot get st_dev/st_ino, so ensure those are 0 or else our test
31433149
# is not set up correctly
31443150
self.assertEqual(0, stat2.st_dev)

0 commit comments

Comments
 (0)