Clarify precision when using NUMBER option in --doctest-modules (#9914)

Fix #9892
This commit is contained in:
MatthewFlamm 2022-05-06 19:25:44 -04:00 committed by GitHub
parent 4ddf48b0a3
commit 5f9d68c8d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -126,14 +126,17 @@ pytest also introduces new options:
in expected doctest output. in expected doctest output.
* ``NUMBER``: when enabled, floating-point numbers only need to match as far as * ``NUMBER``: when enabled, floating-point numbers only need to match as far as
the precision you have written in the expected doctest output. For example, the precision you have written in the expected doctest output. The numbers are
the following output would only need to match to 2 decimal places:: compared using :func:`pytest.approx` with relative tolerance equal to the
precision. For example, the following output would only need to match to 2
decimal places when comparing ``3.14`` to
``pytest.approx(math.pi, rel=10**-2)``::
>>> math.pi >>> math.pi
3.14 3.14
If you wrote ``3.1416`` then the actual output would need to match to 4 If you wrote ``3.1416`` then the actual output would need to match to
decimal places; and so on. approximately 4 decimal places; and so on.
This avoids false positives caused by limited floating-point precision, like This avoids false positives caused by limited floating-point precision, like
this:: this::