test_traceback.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:deb-python-traceback2 作者: openstack 项目源码 文件源码
def test_cause_recursive(self):
        def inner_raise():
            try:
                try:
                    self.zero_div()
                except ZeroDivisionError as e:
                    z = e
                    raise_from(KeyError, e)
            except KeyError as e:
                raise_from(z, e)
        def outer_raise():
            inner_raise() # Marker
        blocks = boundaries.split(self.get_report(outer_raise))
        self.assertEqual(len(blocks), 3)
        self.assertEqual(blocks[1], cause_message)
        # The first block is the KeyError raised from the ZeroDivisionError
        self.assertIn('raise_from(KeyError, e)', blocks[0])
        self.assertNotIn('1/0', blocks[0])
        # The second block (apart from the boundary) is the ZeroDivisionError
        # re-raised from the KeyError
        self.assertIn('inner_raise() # Marker', blocks[2])
        self.check_zero_div(blocks[2])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号