关闭

Python mock UT

163人阅读 评论(0) 收藏 举报
分类:
*mock 的作用非常强大,需要重点研究这个类*
**为什么用 mock.patch.object**

**with as 的用法,先执行with后面的expression ,然后传递值给as 后面的expression ,再执行冒号后的expression**
with mock.patch.object(
            self.agent,'_get_localvtepip') as mock__get_localvtepip:
    with mock.patch.object(
                self.agent,'_syn_localvtepip') as mock__syn_localvtepip:
                mock__syn_localvtepip.return_value = tunnels
                with mock.patch.object(
                    self.agent,'send_tunnel_syncmd') as mock_send_tunnel_syncmd:
                    self.agent._process_all_vxlan_endpoints()
                    mock_send_tunnel_syncmd.assert_called_with('1.2.3.4','add')
def __call__(_mock_self, *args, **kwargs):
        # can't use self in-case a function / method we are mocking uses self
        # in the signature
        _mock_self._mock_check_sig(*args, **kwargs)
        return _mock_self._mock_call(*args, **kwargs)
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1313次
    • 积分:116
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类