擅长:python、mysql、java
<p>小心点!在</p>
<p><a href="http://docs.python.org/dev/library/unittest.mock#calling" rel="nofollow">26.4.2.1. Calling</a></p>
<blockquote>
<p>Mock objects are callable. The call will return the value set as the return_value attribute. The default return value is a new Mock object; it is created the first time the return value is accessed (either explicitly or by calling the Mock) - but it is stored and <strong>the same one returned each time</strong>.</p>
</blockquote>
<p>如果你想让不同的调用得到不同的结果,你需要给你的模拟一个<a href="http://docs.python.org/dev/library/unittest.mock#unittest.mock.Mock.side_effect" rel="nofollow">^{<cd1>}</a>属性。如果<code>mock.side_effect</code>是一个函数,那么<code>mock(*args, **kwargs)</code>将调用<code>mock.side_effect(*args, **kwargs)</code>并返回返回的任何内容。您可以让您的自定义<code>mock.side_effect</code>跟踪哪些调用产生了什么值。在</p>