Using Python 2.6.6
So, I just found out that the following:
myLock.acquire() doStuff() myLock.release()
can be replaced by:
with myLock: doStuff()
My quandry is that with the previous code, I could rule out that the lock was used to protect the work by mocking the Lock. But with the latter, my unittest now (presumably) fails because gets () and release () are not called. So, for the latter case, how can I verify that the lock is used to protect the work?
I prefer the second method because it is not only more concise, but there is no chance that I will write code that forgets to unlock the resource. (Not that I ever did this before ...)
source share