Improve coverage regex pytest-cov (Python)
Problem to solve
Test coverage documentation currently suggests a regex for pytest-cov (Python) which is not so tight and might accidentally catch/accept wrong values. Furthermore it does not work for some scenarios.
Further details
Currently the following regex is suggested
coverage: '/TOTAL.*\s([.\d]+)%/'
This regex also catches faulty percentages, e.g. TOTAL 1337.4242.42.42.%
would be accepted, capturing 1337.4242.42.42.%
Other issues arise when setting coverage --cov-fail-under
and --cov-report
parameters.
As discussed in e.g. just-ci/templates!54 (comment 942401999)
Proposal
To catch above mentioned issues and ensure that the percentage is always valid (and within the 0-100%) range with support for an arbitrary precision I suggest the following regex
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'