def test_raise_key_error(self): def child(): child_var = 2 # noqa: F841 raise Exception() def parent(): parent_var = 1 # noqa: F841 child() with self.assertRaises(KeyError): try: parent() except Exception as e: get_variable_from_exception(e, 'grandchild_var')
def test_get_variable_from_child(self): def child(): child_var = 2 # noqa: F841 raise Exception() def parent(): parent_var = 1 # noqa: F841 child() val = None try: parent() except Exception as e: val = get_variable_from_exception(e, 'child_var') self.assertEqual(val, 2)