diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 24145016ce6..79c21303595 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -235,7 +235,12 @@ def __repr__(self): # If a sensible tolerance can't be calculated, self.tolerance will # raise a ValueError. In this case, display '???'. try: - vetted_tolerance = "{:.1e}".format(self.tolerance) + if isinstance(self.tolerance, int): + vetted_tolerance = "{:n}".format(self.tolerance) + elif self.rel is not None and not math.isinf(self.tolerance): + vetted_tolerance = "{:.1%}".format(self.tolerance / self.expected) + else: + vetted_tolerance = "{:.1e}".format(self.tolerance) if isinstance(self.expected, complex) and not math.isinf(self.tolerance): vetted_tolerance += " ∠ ±180°" except ValueError: