testing.py 文件源码

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

项目:django-icekit 作者: ic-labs 项目源码 文件源码
def setup_with_context_manager(testcase, cm):
    """
    Use a contextmanager in a test setUp that persists until teardown.
    So instead of:

    with ctxmgr(a, b, c) as v:
        # do something with v that only persists for the `with` statement

    use:

    def setUp(self):
        self.v = setup_with_context_manager(self, ctxmgr(a, b, c))

    def test_foo(self):
        # do something with self.v
    """
    val = cm.__enter__()
    testcase.addCleanup(cm.__exit__, None, None, None)
    return val
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号