{"action":"opened","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest/issues/3247","repository_url":"https://api.github.com/repos/pytest-dev/pytest","labels_url":"https://api.github.com/repos/pytest-dev/pytest/issues/3247/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest/issues/3247/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest/issues/3247/events","html_url":"https://github.com/pytest-dev/pytest/issues/3247","id":299145693,"number":3247,"title":"approx on Decimal value fails with default tolerance arguments","user":{"login":"durocher","id":7409782,"avatar_url":"https://avatars2.githubusercontent.com/u/7409782?v=4","gravatar_id":"","url":"https://api.github.com/users/durocher","html_url":"https://github.com/durocher","followers_url":"https://api.github.com/users/durocher/followers","following_url":"https://api.github.com/users/durocher/following{/other_user}","gists_url":"https://api.github.com/users/durocher/gists{/gist_id}","starred_url":"https://api.github.com/users/durocher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/durocher/subscriptions","organizations_url":"https://api.github.com/users/durocher/orgs","repos_url":"https://api.github.com/users/durocher/repos","events_url":"https://api.github.com/users/durocher/events{/privacy}","received_events_url":"https://api.github.com/users/durocher/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-21T22:03:11Z","updated_at":"2018-02-21T22:03:11Z","closed_at":null,"author_association":"NONE","body":"When using default tolerance on a Decimal, approx fails:\r\n```\r\n>>> from pytest import approx\r\n>>> from decimal import Decimal\r\n>>> approx(Decimal('1'))\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/Users/mike/temp/env/lib/python3.6/site-packages/_pytest/python_api.py\", line 175, in __repr__\r\n    vetted_tolerance = '{:.1e}'.format(self.tolerance)\r\n  File \"/Users/mike/temp/env/lib/python3.6/site-packages/_pytest/python_api.py\", line 244, in tolerance\r\n    relative_tolerance = set_default(self.rel, 1e-6) * abs(self.expected)\r\nTypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'\r\n>>> import sys\r\n>>> sys.version\r\n'3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) \\n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'\r\n>>> import pytest\r\n>>> pytest.__version__\r\n'3.4.1'\r\n```\r\nbut it works fine with `rel` and/or `abs`:\r\n```\r\n>>> approx(foo, rel=Decimal('1e-6'))\r\n1 ± 1.0e-6\r\n>>> approx(foo, abs=Decimal('1e-12'))\r\n1 ± 1.0e-12\r\n```\r\n\r\n```\r\n$ pip list\r\nDEPRECATION: 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.\r\nattrs (17.4.0)\r\npip (9.0.1)\r\npluggy (0.6.0)\r\npy (1.5.2)\r\npytest (3.4.1)\r\nsetuptools (38.5.1)\r\nsix (1.11.0)\r\ntox (2.9.1)\r\nvirtualenv (15.1.0)\r\nwheel (0.30.0)\r\n```\r\n"}}
{"actor":{"display_login":"durocher"}}