File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -347,7 +347,7 @@ def _acquire(self):
347
347
try :
348
348
fd = os .open (self ._lock_file , open_mode )
349
349
except OSError :
350
- pass
350
+ raise
351
351
else :
352
352
try :
353
353
msvcrt .locking (fd , msvcrt .LK_NBLCK , 1 )
Original file line number Diff line number Diff line change @@ -366,6 +366,28 @@ class FileLockTest(BaseTest, unittest.TestCase):
366
366
367
367
LOCK_TYPE = filelock .FileLock
368
368
LOCK_PATH = "test.lock"
369
+ LOCK_PATH_UNWRITABLE = "test.lock.unwritable"
370
+
371
+ @classmethod
372
+ def setUpClass (cls ):
373
+ try :
374
+ os .mkdir (cls .LOCK_PATH_UNWRITABLE , 0 )
375
+ except :
376
+ cls .fail ("Could not create unwritable directory" )
377
+
378
+ def test_write_fail (self ):
379
+ """Ensures graceful failure of lock when path not writable."""
380
+ lock1 = self .LOCK_TYPE ("{}/test" .format (self .LOCK_PATH_UNWRITABLE ))
381
+ with self .assertRaises (OSError ):
382
+ lock1 .acquire ()
383
+
384
+ @classmethod
385
+ def tearDownClass (cls ):
386
+ """Clean up."""
387
+ try :
388
+ os .rmdir (cls .LOCK_PATH_UNWRITABLE )
389
+ except :
390
+ pass
369
391
370
392
371
393
class SoftFileLockTest (BaseTest , unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments