python-genbadge icon indicating copy to clipboard operation
python-genbadge copied to clipboard

support coverage badge generation from pytest --junitxml file

Open pixelpicnic opened this issue 1 year ago • 2 comments

It would be great if we could leverage the same xml from the pytest report generation to generate the coverage badge without needing to install the coverage module.

currently the workflow would be:

# generate reports:
# test report
pytest --cov-report=html:reports/coverage --junitxml=reports/coverage/pytest_coverage.xml
# coverage report
coverage xml -o reports/coverage/coverage.xml

# generate badges
# tests badge
genbadge tests -i < reports/coverage/pytest_coverage.xml -o reports/badges/tests-badge.svg
# coverage badge
genbadge coverage -i reports/coverage/coverage.xml -o reports/badges/coverage-badge.svg

is it possible to consolidate these steps?

pytest --cov-report=html:reports/coverage --junitxml=reports/coverage/pytest_coverage.xml
genbadge tests coverage -i reports/coverage/pytest_coverage.xml -o reports/coverage/

where -o reports/coverage/ will generate badges with default names, and specifying names would require badges to be generated individually.

appreciate the project! Thanks very much

pixelpicnic avatar Feb 16 '24 05:02 pixelpicnic

Thanks @pixelpicnic for the suggestion!

without needing to install the coverage module

pytest-cov is just a tiny wrapper of coverage so you install it already :) : https://github.com/pytest-dev/pytest-cov/blob/master/setup.py#L133

Does it change your opinion about this feature ? Otherwise I'll accept any non-destructive PR (i.e. all existing features must continue to work as is) that would implement it.

You might need to leverage click's multi command design https://stackoverflow.com/a/59391691/7262247 , hopefully this won't get too complex.

smarie avatar Mar 11 '24 14:03 smarie

Cheers @smarie, I'll give that a shot. Thanks for the info!

pixelpicnic avatar Mar 12 '24 04:03 pixelpicnic