test_contextlib2.py 文件源码

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

项目:contextlib2 作者: jazzband 项目源码 文件源码
def test_contextmanager_except_pep479(self):
        code = """\
from __future__ import generator_stop
from contextlib import contextmanager
@contextmanager
def woohoo():
    yield
"""
        locals = {}
        exec(code, locals, locals)
        woohoo = locals['woohoo']

        stop_exc = StopIteration('spam')
        try:
            with woohoo():
                raise stop_exc
        except Exception as ex:
            self.assertIs(ex, stop_exc)
        else:
            self.fail('StopIteration was suppressed')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号