diff tests/test-lock.py @ 32279:68c43a416585

tests: use context manager form of assertRaises Support for using unittest.TestCase.assertRaises as a context manager was added in Python 2.7. This form is more readable, especially for complex tests. While I was here, I also restored the use of assertRaisesRegexp, which was removed in c6921568cd20 for Python 2.6 compatibility.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 13 May 2017 11:52:44 -0700
parents 0d892d820a51
children daf12f69699f
line wrap: on
line diff
--- a/tests/test-lock.py	Sat May 13 11:42:42 2017 -0700
+++ b/tests/test-lock.py	Sat May 13 11:52:44 2017 -0700
@@ -260,12 +260,10 @@
         lock = state.makelock(inheritchecker=check)
         state.assertacquirecalled(True)
 
-        def tryinherit():
+        with self.assertRaises(error.LockInheritanceContractViolation):
             with lock.inherit():
                 pass
 
-        self.assertRaises(error.LockInheritanceContractViolation, tryinherit)
-
         lock.release()
 
     def testfrequentlockunlock(self):