nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
2.96k stars 426 forks source link

Consider changing default value for precision from 0 to 2 #1721

Closed dolfinus closed 8 months ago

dolfinus commented 8 months ago

Is your feature request related to a problem? Please describe.

I was always wondering why all my coverage reports shows coverage percentage as float but without fraction part. E.g. `92.00%.

After diving into source code, I found that reported coverage is almost always rounded, and default value for precision is 0: https://github.com/nedbat/coveragepy/blob/962429ce7c160e8b476cc610288f58206c629138/coverage/results.py#L191

Describe the solution you'd like

Change default value for precision to 2.

Describe alternatives you've considered

Additional context

nedbat commented 8 months ago

Help me understand: what coverage reports are you using? With the default precision of 0, you should see 92%, not 92.00%.

dolfinus commented 8 months ago

Sorry, my bad, report shows just 92%, not 92.00%:

Name                            Stmts   Miss Branch BrPart  Cover
-----------------------------------------------------------------
horizon/__init__.py                 1      0      0      0   100%
horizon/backend/__init__.py        31      2      2      1    91%
horizon/backend/api/__init__.py     0      0      0      0   100%
horizon/backend/api/handlers.py    48      7      6      2    83%
....
-----------------------------------------------------------------
TOTAL                            1860    117    354     44    92%

With precisiion = 2:

Name                              tmts   Miss Branch BrPart   Cover
-------------------------------------------------------------------
horizon/__init__.py                  3      0      0      0 100.00%
horizon/backend/__init__.py         31      2      2      1  90.91%
horizon/backend/api/__init__.py      0      0      0      0 100.00%
horizon/backend/api/handlers.py     48      7      6      2  83.33%
...
-------------------------------------------------------------------
TOTAL                             1913    122    368     47  91.80%

This is from different branches of my project, so numbers are slightly different

nedbat commented 8 months ago

OK, thanks. I don't think most people want more precision in their numbers. The setting is there so that you can get the precision you want. I think the default of 0 is still appropriate.