test_contextlib2.py 文件源码

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

项目:contextlib2 作者: jazzband 项目源码 文件源码
def test_contextmanager_as_decorator(self):
        @contextmanager
        def woohoo(y):
            state.append(y)
            yield
            state.append(999)

        state = []
        @woohoo(1)
        def test(x):
            self.assertEqual(state, [1])
            state.append(x)
        test('something')
        self.assertEqual(state, [1, 'something', 999])

        # Issue #11647: Ensure the decorated function is 'reusable'
        state = []
        test('something else')
        self.assertEqual(state, [1, 'something else', 999])

# Detailed exception chaining checks only make sense on Python 3
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号