Skip to content

Commit 1976eb4

Browse files
committed
feat: add support to start/stop on lock test helper
1 parent 4543860 commit 1976eb4

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

drf_kit/tests.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ def __init__(self):
129129
self.call_args = []
130130
self.call_kwargs = {}
131131

132+
def start(self):
133+
setattr(ConnectionProxy, "lock", mocked_lock)
134+
135+
def stop(self):
136+
delattr(ConnectionProxy, "lock")
137+
138+
def __enter__(self):
139+
self.start()
140+
return self
141+
142+
def __exit__(self, exc_type, exc_val, exc_tb):
143+
self.stop()
144+
132145
def assert_called(self):
133146
msg = "Expected to be called, but it was not"
134147
assert self.call_count > 0, msg
@@ -174,10 +187,4 @@ def mocked_lock(*lock_args, **lock_kwargs):
174187

175188
yield
176189

177-
@contextmanager
178-
def lock_assertion():
179-
setattr(ConnectionProxy, "lock", mocked_lock)
180-
yield assertion
181-
delattr(ConnectionProxy, "lock")
182-
183-
return lock_assertion()
190+
return assertion

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "drf-kit"
3-
version = "1.8.0"
3+
version = "1.8.1"
44
description = "DRF Toolkit"
55
authors = ["eduK <[email protected]>"]
66
packages = [

test_app/tests/tests_test_helpers.py

+9
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,12 @@ def _effect():
9595
tasks.LockableTask().run()
9696

9797
lock.assert_called()
98+
99+
def test_use_with_start(self):
100+
lock = self.patch_cache_lock()
101+
lock.start()
102+
103+
tasks.LockableTask().run()
104+
lock.assert_called()
105+
106+
lock.stop()

0 commit comments

Comments
 (0)