From f458ad036b7fc01bee3141ac71304519d218b013 Mon Sep 17 00:00:00 2001 From: marqh Date: Thu, 27 Oct 2016 18:07:19 +0000 Subject: [PATCH] limit filelock use --- lib/iris/tests/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/iris/tests/__init__.py b/lib/iris/tests/__init__.py index d8834baa783..d0b065076d3 100644 --- a/lib/iris/tests/__init__.py +++ b/lib/iris/tests/__init__.py @@ -804,10 +804,17 @@ def check_graphic(self): """ fname = os.path.join(_RESULT_PATH, 'imagerepo.lock') - lock = filelock.FileLock(fname) - # The imagerepo.json file is a critical resource, so ensure thread + # The imagerepo.json file is a critical resource, during development. So, + # if the file is writeable, or it doesn't exist but could be written, ensure thread # safe read/write behaviour via platform independent file locking. - with lock.acquire(timeout=600): + # Otherwise, do not lock, as this prevents tests being run without + # write permissions to this _RESULT_PATH location. + if (os.access(fname, os.W_OK) or + (not os.access(fname, os.R_OK) and os.access(_RESULT_PATH, os.W_OK))): + lock = filelock.FileLock(fname) + with lock.acquire(timeout=600): + self._assert_graphic() + else: self._assert_graphic() def _remove_testcase_patches(self):