GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pytest.approx(Decimal(...)) Causes decimal.FloatOperation in __repr__ (pytest 8.4.0+) · Issue #13530 · pytest-dev/pytest Closed Descriptionpytest.approx() with decimal.Decimal objects triggers a decimal.FloatOperation error when the ApproxDecimal object's repr method is called (e.g., during print() or assertion formatting). This happens because ApproxDecimal.repr compares its Decimal tolerance with hardcoded float literals (like 1e-3, 1e3). When the decimal context traps FloatOperations (to maintain Decimal precision), these implicit float-Decimal comparisons raise an error. This issue started with pytest version 8.4.0 and seems related to changes from Issue #13010. Pytest 8.4.0 # test_decimal_approx.py import decimal import pytest decimal.getcontext().traps[decimal.FloatOperation] = True def test_decimal_approx_repr_issue(): """Reproduces the decimal.FloatOperation error from pytest.approx(Decimal)'s repr.""" approx_obj = pytest.approx(decimal.Decimal("2.60")) print(f"Attempting to represent pytest.approx(Decimal): {approx_obj}") # Triggers the bug assert decimal.Decimal("2.600001") == approx_obj # You can run this test with: # python -m pytest test_decimal_approx.py Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |