def test_exception(self): e = None try: try: raise ValueError() except Exception: raise messaging.ExpectedException() except messaging.ExpectedException as e: self.assertIsInstance(e, messaging.ExpectedException) self.assertTrue(hasattr(e, 'exc_info')) self.assertIsInstance(e.exc_info[1], ValueError)
def _object_dispatch(self, target, method, context, args, kwargs): """Dispatch a call to an object method. This ensures that object methods get called and any exception that is raised gets wrapped in an ExpectedException for forwarding back to the caller (without spamming the conductor logs). """ try: # NOTE(danms): Keep the getattr inside the try block since # a missing method is really a client problem return getattr(target, method)(context, *args, **kwargs) except Exception: raise messaging.ExpectedException()