擅长:python、mysql、java
<p>据我所知,您需要的是一个<strong>嘲弄</strong>(参见<a href="https://stackoverflow.com/questions/2665812/what-is-mocking">What is Mocking?</a>和<a href="https://en.wikipedia.org/wiki/Mock_object" rel="nofollow noreferrer">Mock Object</a>)。好吧,下面列出几个选项:</p>
<ul>
<li><p>如果您打算只模拟请求包,请使用<a href="https://pypi.python.org/pypi/requests-mock" rel="nofollow noreferrer">requests-mock library</a>,它旨在模拟请求包中的响应。</p></li>
<li><p>另一个选择是使用python<a href="https://pypi.python.org/pypi/mock" rel="nofollow noreferrer"><strong>mock libary</strong></a>来模拟<code>requests</code>模块,另请参见<a href="https://www.toptal.com/python/an-introduction-to-mocking-in-python" rel="nofollow noreferrer">An Introduction to Mocking in Python
</a>。</p></li>
</ul>