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

Simplified Fix for Repr #7123

Closed
wants to merge 8 commits into from
7 changes: 6 additions & 1 deletion src/_pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down