*mock 的作用非常强大,需要重点研究这个类*
**为什么用 mock.patch.object**
**withas 的用法,先执行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)