Improve error message for invalid types passed to pytest.approx()

* Hide the internal traceback
* Use !r representation instead of !s (the default for {} formatting)
This commit is contained in:
Bruno Oliveira 2018-07-31 21:08:24 -03:00
parent 327fe4cfcc
commit bf7c188cc0
1 changed files with 3 additions and 1 deletions

View File

@ -34,7 +34,7 @@ def _cmp_raises_type_error(self, other):
def _non_numeric_type_error(value):
return TypeError(
"cannot make approximate comparisons to non-numeric values, e.g. {}".format(
"cannot make approximate comparisons to non-numeric values, e.g. {!r}".format(
value
)
)
@ -507,6 +507,8 @@ def approx(expected, rel=None, abs=None, nan_ok=False):
# class provides some convenient methods and overloads, but isn't really
# essential.
__tracebackhide__ = True
if isinstance(expected, Decimal):
cls = ApproxDecimal
elif isinstance(expected, Number):