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

pytest.approx: Please improve repr readability #6985

Closed
henzef opened this issue Mar 30, 2020 · 5 comments · Fixed by #12665
Closed

pytest.approx: Please improve repr readability #6985

henzef opened this issue Mar 30, 2020 · 5 comments · Fixed by #12665
Labels
good first issue easy issue that is friendly to new contributor topic: reporting related to terminal output and user-facing messages and errors type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@henzef
Copy link

henzef commented Mar 30, 2020

It seems that pytest.approx repr is optimized for very high or very low tolerances, but is not as easily readable as it could be for values in between.
Some examples:

  • pytest.approx(42, abs=1) repr is 42 ± 1.0e+00, which could be just 42 ± 1.
  • pytest.approx(5, rel=0.01) repr is 5 ± 5.0e-02, but could be 5 ± 0.05 or maybe even 5 ± 1%
  • pytest.approx(24000, abs=500) repr is 24000 ± 5.0e+02 and could be 24000 ± 500
  • removing accuracy example: pytest.approx(1500, abs=555) repr is 1500 ± 5.6e+02 and could be 1500 ± 555

In these number ranges using the exact number instead of the exponential notation is both more accurate and easier readable for humans. Please adapt pytest.approx to switch it's repr style according to the input value ranges.

@hodevin
Copy link

hodevin commented Mar 30, 2020

Hey, my team and I would like to look over this issue and resolve it if that's okay.

@kalekundert
Copy link
Contributor

Of course, PRs are always welcome! Hopefully this one won't be too hard, either.

@Zac-HD Zac-HD added topic: reporting related to terminal output and user-facing messages and errors type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature labels Mar 31, 2020
@Zac-HD
Copy link
Member

Zac-HD commented Mar 31, 2020

See https://docs.python.org/3/library/string.html#format-specification-mini-language - you probably want to use the n format specifier.

@henzef

This comment was marked as spam.

@Zac-HD Zac-HD added the good first issue easy issue that is friendly to new contributor label Jul 6, 2024
@fazeelghafoor
Copy link
Contributor

@Zac-HD is this issue still open, I would like to work on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor topic: reporting related to terminal output and user-facing messages and errors type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants