擅长:python、mysql、java
<p>我注意到这个问题是关于py.test的。test 3.0包含一个<code>approx()</code>函数(好吧,真的是一个类),对于这个目的非常有用。</p>
<pre class="lang-py prettyprint-override"><code>import pytest
assert 2.2 == pytest.approx(2.3)
# fails, default is ± 2.3e-06
assert 2.2 == pytest.approx(2.3, 0.1)
# passes
# also works the other way, in case you were worried:
assert pytest.approx(2.3, 0.1) == 2.2
# passes
</code></pre>
<p>文档在这里:<a href="https://docs.pytest.org/en/latest/reference.html#pytest-approx" rel="noreferrer">https://docs.pytest.org/en/latest/reference.html#pytest-approx</a></p>