Python mock UT
*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)
阅读更多
个人分类: UT
想对作者说点什么? 我来说一句

PowerMockAtOredev

2010年02月11日 166KB 下载

没有更多推荐了,返回首页

不良信息举报

Python mock UT

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭