diff --git a/taskflow/tests/unit/test_utils_failure.py b/taskflow/tests/unit/test_utils_failure.py index 841b980e..ef90a150 100644 --- a/taskflow/tests/unit/test_utils_failure.py +++ b/taskflow/tests/unit/test_utils_failure.py @@ -99,6 +99,13 @@ class ReCreatedFailureTestCase(test.TestCase, GeneralFailureObjTestsMixin): self.assertIs(exc.check(RuntimeError), RuntimeError) +class FromExceptionTestCase(test.TestCase, GeneralFailureObjTestsMixin): + + def setUp(self): + super(FromExceptionTestCase, self).setUp() + self.fail_obj = misc.Failure.from_exception(RuntimeError('Woot!')) + + class FailureObjectTestCase(test.TestCase): def test_dont_catch_base_exception(self): diff --git a/taskflow/utils/misc.py b/taskflow/utils/misc.py index af472733..629927e4 100644 --- a/taskflow/utils/misc.py +++ b/taskflow/utils/misc.py @@ -416,6 +416,10 @@ class Failure(object): 'Failure.__init__ got unexpected keyword argument(s): %s' % ', '.join(six.iterkeys(kwargs))) + @classmethod + def from_exception(cls, exception): + return cls((type(exception), exception, None)) + def _matches(self, other): if self is other: return True