Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

approx on Decimal value fails with default tolerance arguments #3247

Closed
durocher opened this issue Feb 21, 2018 · 0 comments
Closed

approx on Decimal value fails with default tolerance arguments #3247

durocher opened this issue Feb 21, 2018 · 0 comments

Comments

@durocher
Copy link
Contributor

When using default tolerance on a Decimal, approx fails:

>>> from pytest import approx
>>> from decimal import Decimal
>>> approx(Decimal('1'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mike/temp/env/lib/python3.6/site-packages/_pytest/python_api.py", line 175, in __repr__
    vetted_tolerance = '{:.1e}'.format(self.tolerance)
  File "/Users/mike/temp/env/lib/python3.6/site-packages/_pytest/python_api.py", line 244, in tolerance
    relative_tolerance = set_default(self.rel, 1e-6) * abs(self.expected)
TypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'
>>> import sys
>>> sys.version
'3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
>>> import pytest
>>> pytest.__version__
'3.4.1'

but it works fine with rel and/or abs:

>>> approx(foo, rel=Decimal('1e-6'))
1 ± 1.0e-6
>>> approx(foo, abs=Decimal('1e-12'))
1 ± 1.0e-12
$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
attrs (17.4.0)
pip (9.0.1)
pluggy (0.6.0)
py (1.5.2)
pytest (3.4.1)
setuptools (38.5.1)
six (1.11.0)
tox (2.9.1)
virtualenv (15.1.0)
wheel (0.30.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant