From 61a7ed5ff09dd400489925ecc721a4c248ec9b65 Mon Sep 17 00:00:00 2001 From: Jane Fan Date: Fri, 15 Jun 2018 03:54:53 +0000 Subject: [PATCH 1/2] Change the pytest_lab_aquire_lock to acquire lock according to the wait_on_lock option --- pytest_lab/locker.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pytest_lab/locker.py b/pytest_lab/locker.py index 4e062b6..e8a2c6d 100644 --- a/pytest_lab/locker.py +++ b/pytest_lab/locker.py @@ -173,7 +173,16 @@ def pytest_unconfigure(self, config): @pytest.hookimpl def pytest_lab_aquire_lock(self, config, identifier): - self.aquire(identifier) + wait_on_lock = config.getoption('--wait-on-locks') + if not wait_on_lock: + self.aquire(identifier) + else: + while wait_on_lock: + try: + if self.acquire(identifier): + break + except ResourceLocked: + pass return True @pytest.hookimpl From 999817b2c89143c19725adcfa3f7884ce8624f44 Mon Sep 17 00:00:00 2001 From: Jane Fan Date: Fri, 15 Jun 2018 15:23:52 +0000 Subject: [PATCH 2/2] Add the wait-on-locks option --- pytest_lab/locker.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pytest_lab/locker.py b/pytest_lab/locker.py index e8a2c6d..69768ea 100644 --- a/pytest_lab/locker.py +++ b/pytest_lab/locker.py @@ -114,6 +114,12 @@ def release(self, key): pass +@pytest.hookimpl +def pytest_addoption(parser): + parser.addoption('--wait-on-locks', action='store_true', default=False, + help='Wait for the locks until it is available') + + class Locker(object): def __init__(self, config, backend, ttl=30): self.config = config @@ -179,7 +185,7 @@ def pytest_lab_aquire_lock(self, config, identifier): else: while wait_on_lock: try: - if self.acquire(identifier): + if self.aquire(identifier): break except ResourceLocked: pass