擅长:python、mysql、java
<p>有许多<a href="http://www.voidspace.org.uk/python/mock/mock.html#mock.Mock.return_value" rel="nofollow noreferrer">mock attributes</a>要使用,您可以稍微更改补丁装饰器的用法,如下所示:</p>
<pre><code>class Tester(unittest.TestCase):
def test_xmlrpclib(self):
with patch('library.xmlrpclib.ServerProxy.isTokenValid') as isTokenValid:
self.assertEqual(isTokenValid.call_count, 0)
# your test code calling xmlrpclib
self.assertEqual(isTokenValid.call_count, 1)
token = isTokenValid.call_args[0] # assume this token is valid
self.assertEqual(isTokenValid.return_value, 1)
</code></pre>
<p>您可以调整上面的代码以满足您的需求。在</p>