test_utils.py 文件源码

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

项目:charm-neutron-openvswitch 作者: openstack 项目源码 文件源码
def patch_open():
    '''Patch open() to allow mocking both open() itself and the file that is
    yielded.

    Yields the mock for "open" and "file", respectively.'''
    mock_open = MagicMock(spec=open)
    mock_file = MagicMock(spec=io.FileIO)

    @contextmanager
    def stub_open(*args, **kwargs):
        mock_open(*args, **kwargs)
        yield mock_file

    with patch('builtins.open', stub_open):
        yield mock_open, mock_file
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号