Skip to content

Commit 0e511e1

Browse files
authored
Update getting-started.rst
1 parent 0b94d20 commit 0e511e1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

doc/en/getting-started.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
202223
Request a unique temporary directory for functional tests
203224
--------------------------------------------------------------
204225

0 commit comments

Comments
 (0)