[FIX] tests: make self.assertRaises() return the expected object

This commit is contained in:
Raphael Collet 2014-11-17 15:39:14 +01:00
parent 908252ec88
commit 86ba01976e
2 changed files with 5 additions and 3 deletions

View File

@ -111,10 +111,12 @@ class TestACL(common.TransactionCase):
# accessing fields must no raise exceptions...
part.name
# ... except if they are restricted
with self.assertRaises(openerp.exceptions.AccessError):
with self.assertRaises(openerp.osv.orm.except_orm) as cm:
with mute_logger('openerp.models'):
part.email
self.assertEqual(cm.exception.args[0], 'AccessError')
if __name__ == '__main__':
unittest2.main()

View File

@ -108,9 +108,9 @@ class BaseCase(unittest2.TestCase):
@contextmanager
def _assertRaises(self, exception):
""" Context manager that clears the environment upon failure. """
with super(BaseCase, self).assertRaises(exception):
with super(BaseCase, self).assertRaises(exception) as cm:
with self.env.clear_upon_failure():
yield
yield cm
def assertRaises(self, exception, func=None, *args, **kwargs):
if func: