Visitar URL original
Merge pull request #15006 from RonnyPfannschmidt/fix-15005-decimal-ou… · pytest-dev/pytest@86c6c35 · GitHub
Skip to content

Commit 86c6c35

Browse files
Merge pull request #15006 from RonnyPfannschmidt/fix-15005-decimal-outside-float-range
approx: Decimal and numpy cleanup
2 parents ff42276 + bccb2f2 commit 86c6c35

10 files changed

Lines changed: 409 additions & 45 deletions

File tree

‎changelog/15005.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`pytest.approx` no longer treats finite :class:`~decimal.Decimal` values outside the :class:`float` range (such as ``Decimal("1e400")``) as infinite, which made in-tolerance comparisons fail.

‎changelog/15006.bugfix.1.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The failure message for :func:`pytest.approx` comparisons of :class:`~decimal.Decimal` collections no longer reports ``Max absolute difference: -inf``, or crashes for mappings, when the :class:`decimal.FloatOperation` trap is set.

‎changelog/15006.bugfix.2.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`pytest.approx` no longer raises ``AttributeError`` when comparing :class:`numpy.ndarray` instances with ``object`` dtype, such as arrays of :class:`~decimal.Decimal`.

‎changelog/15006.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restored the tolerance shown by :func:`pytest.approx` for :class:`~decimal.Decimal` values, which since 9.0 displayed ``???`` for the default tolerance and reported the raw ``rel`` ratio instead of the absolute tolerance actually compared against.

‎changelog/15006.improvement.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`pytest.approx` now emits :class:`pytest.PytestApproxDecimalToleranceWarning` when a ``rel`` or ``abs`` tolerance is given as a :class:`float` that cannot be represented exactly for a :class:`~decimal.Decimal` comparison, since such a tolerance is widened to the float's exact binary value.

‎doc/en/reference/reference.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,9 @@ Custom warnings generated in some situations such as improper usage or deprecate
12901290
.. autoclass:: pytest.PytestWarning
12911291
:show-inheritance:
12921292

1293+
.. autoclass:: pytest.PytestApproxDecimalToleranceWarning
1294+
:show-inheritance:
1295+
12931296
.. autoclass:: pytest.PytestAssertRewriteWarning
12941297
:show-inheritance:
12951298

0 commit comments

Comments
 (0)