File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,27 @@ This is outlined below:
199199
200200 Note that attributes added at class level are *class attributes *, so they will be shared between tests.
201201
202+ Compare floating-point values with pytest.approx
203+ --------------------------------------------------------------
204+
205+ .. note ::
206+
207+ ``pytest `` also provides a number of utilities to make writing tests easier.
208+ For example, you can use :func: `pytest.approx ` to compare floating-point
209+ values that may have small rounding errors:
210+
211+ .. code-block :: python
212+
213+ # content of test_approx.py
214+ import pytest
215+
216+ def test_sum ():
217+ assert (0.1 + 0.2 ) == pytest.approx(0.3 )
218+
219+ This avoids the need for manual tolerance checks or using
220+ ``math.isclose `` and works with scalars, lists, and NumPy arrays.
221+
222+
202223Request a unique temporary directory for functional tests
203224--------------------------------------------------------------
204225
You can’t perform that action at this time.
0 commit comments