Skip to content

Commit b9aaf8b

Browse files
committed
Tweak filelock tests for Windows
In the tests where we "fake" someone else holding the lock by just creating the lockfile, close the phony lockfile after the test so Windows dowsn't get file access errors. Signed-off-by: Mats Wichmann <mats@linux.com>
1 parent e6efb98 commit b9aaf8b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

SCons/Util/filelockTests.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def tearDown(self):
5252
with suppress(FileNotFoundError):
5353
os.unlink(self.lockfile)
5454

55-
def _fakelock(self):
55+
def _fakelock(self) -> int:
5656
"""Create a fake lockfile to simulate a busy lock."""
57-
_ = os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR)
57+
return os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR)
5858

5959
def test_context_manager_lock(self):
6060
"""Test acquiring a file lock, context manager."""
@@ -81,16 +81,18 @@ def test_acquire_release_lock(self):
8181
def test_nonblocking_lockfail(self):
8282
"""Test non-blocking acquiring a busy file lock."""
8383
self.lock = filelock.FileLock(self.file, writer=True)
84-
self._fakelock()
84+
fd = self._fakelock()
8585
with self.lock and self.assertRaises(filelock.AlreadyLockedError):
8686
self.lock.acquire_lock()
87+
os.close(fd)
8788

8889
def test_timeout_lockfail(self):
8990
"""Test blocking acquiring a busy file lock with timeout."""
9091
self.lock = filelock.FileLock(self.file, writer=True, timeout=1)
91-
self._fakelock()
92+
fd = self._fakelock()
9293
with self.lock and self.assertRaises(filelock.LockTimeoutError):
9394
self.lock.acquire_lock()
95+
os.close(fd)
9496

9597
if __name__ == "__main__":
9698
unittest.main()

0 commit comments

Comments
 (0)