def run_with_enhanced_exception(self, extra_msg_fn, try_block_fn, expected_exc_type=None): expected_exc_type = expected_exc_type or TestException orig_format_exc = None with self.assertRaises(expected_exc_type) as ex: with enhance_exception(extra_msg_fn): try: try_block_fn() except: orig_format_exc = traceback.format_exc() raise final_format_exc = traceback.format_exc() self.assertNotEqual(None, orig_format_exc, 'did not run') self.assert_contains(needle=orig_format_exc, haystack=final_format_exc, msg='orig format is always contained') return orig_format_exc, final_format_exc
def test_if_there_is_no_error_nothing_is_raised(self): x = False with enhance_exception(lambda: 'extra info'): x = True self.assertTrue(x)
def json_loads(self, content): with enhance_exception(lambda: content): return json.loads(content, object_pairs_hook=od)