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

add option to generate test coverage report without codecov #207

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

zacharyburnett
Copy link
Contributor

@zacharyburnett zacharyburnett commented Jun 9, 2024

using the guide here: https://hynek.me/articles/ditch-codecov-python/

This does not create coverage diffs or report to PRs, just creates a markdown summary table

closes #189

EDIT: here's what the summary table looks like:
image

@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch from 8a31636 to fba02a5 Compare June 9, 2024 17:06
@Cadair
Copy link
Member

Cadair commented Jun 10, 2024

I tried this out on sunpy and it seems to explode. sunpy/sunpy#7668

@Cadair
Copy link
Member

Cadair commented Jun 10, 2024

It seems that it's not picking up the coverage.xml to upload here: https://github.com/sunpy/sunpy/actions/runs/9445798095/job/26014155532?pr=7668#step:14:16 🤔

Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for taking a swing at this!

.github/workflows/tox.yml Outdated Show resolved Hide resolved
.github/workflows/tox.yml Outdated Show resolved Hide resolved
- run: python -Im pip install --upgrade coverage[toml]
- run: python -Im coverage combine
- run: python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to add the ability to fail this job based on either total coverage % or diff coverage %.

@pllim
Copy link
Contributor

pllim commented Jun 10, 2024

tl;dr -- this does not generate patch coverage, right?

@Cadair
Copy link
Member

Cadair commented Jun 10, 2024

Not yet, but I found a way to make it.

@zacharyburnett
Copy link
Contributor Author

tl;dr -- this does not generate patch coverage, right?

Not yet, but I found a way to make it.

For patch coverage we'd need to store the coverage from main somewhere, to compare it to; some people I've seen online have done that by storing it in a hidden page in the repository's wiki, reading and writing it with a github token with ${{ secrets.GITHUB_TOKEN }}

@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch from 325b539 to 156160e Compare June 10, 2024 17:59
tools/tox_matrix.py Outdated Show resolved Hide resolved
@pllim
Copy link
Contributor

pllim commented Jun 11, 2024

@zacharyburnett
Copy link
Contributor Author

I am trying this out too at spacetelescope/acstools#205 and it still crashes:

https://github.com/spacetelescope/acstools/actions/runs/9463279566/job/26068438067?pr=205

oh whoops, I fixed the artifact issue:
image
but didn't pass any filenames to coverage combine 😅
image

@pllim

This comment was marked as resolved.

@pllim

This comment was marked as outdated.

@pllim

This comment was marked as outdated.

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

Even when CI passes, it failed with the same error.

Coverage XML written to file coverage.xml

mv: cannot stat '.coverage': No such file or directory

@pllim pllim mentioned this pull request Jun 12, 2024
@zacharyburnett
Copy link
Contributor Author

Even when CI passes, it failed with the same error.

Coverage XML written to file coverage.xml

mv: cannot stat '.coverage': No such file or directory

it should be uploading / downloading the .coverage database, to be able to combine multiple machine types, so if that's not present then something is messed up

@zacharyburnett
Copy link
Contributor Author

zacharyburnett commented Jun 12, 2024

it looks like --cov-report=xml is what's creating the coverage.xml; however, it should still be creating a .coverage database file... I'll so some local testing to see what files it spits out
https://github.com/spacetelescope/acstools/actions/runs/9463279566/job/26118526244#step:10:105

pytest --pyargs acstools --cov-report=xml --cov=acstools /home/runner/work/acstools/acstools/doc --cov --remote-data -v

@zacharyburnett
Copy link
Contributor Author

running pytest --pyargs acstools --cov-report=xml --cov=acstools --cov --remote-data -v locally does appear to create the .coverage file:

❯ ls -a
.							CITATION.md
..							CODE_OF_CONDUCT.md
.bandit.yaml						LICENSE.md
.coverage						MANIFEST.in
.coverage.urelialia2022.local.stsci.edu.35749.XCMKciAx	README.rst
.git							__pycache__
.github							acstools
.gitignore						acstools.egg-info
.mypy_cache						conftest.py
.pytest_cache						coverage.xml
.readthedocs.yaml					doc
.tmp							pyproject.toml
.tox							tox.ini

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

What is the difference between .coverage and coverage.xml?

@zacharyburnett
Copy link
Contributor Author

zacharyburnett commented Jun 12, 2024

What is the difference between .coverage and coverage.xml?

I'm not intimately familiar with it, but as far as I know .coverage is a SQLite database file with support for parallel-mode (storing coverage for multiple machine configurations / runs) while coverage.xml is report-focused and so is expected to only contain results from a single run.

We could use coverage.xml, but then we'd need to have a summary table of coverage for each and every run, instead of a single table collating all runs

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

Tried to debug at #209 but no luck. I see the coverage ran but the the upload failed: https://github.com/spacetelescope/acstools/actions/runs/9483014271/job/26134042811?pr=205

@zacharyburnett
Copy link
Contributor Author

Tried to debug at #209 but no luck. I see the coverage ran but the the upload failed: https://github.com/spacetelescope/acstools/actions/runs/9483014271/job/26134042811?pr=205

could you also add -a to the ls?

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch from 242272f to 88ebba9 Compare December 2, 2024 13:56

- if: ${{ (success() || failure()) && contains(matrix.coverage, 'github') && matrix.pytest == 'true' }}
name: add run info to coverage filename
run: mv $(find ~ -name .coverage) .coverage.${{ github.sha }}-${{ runner.os }}-${{ runner.arch }}-${{ matrix.toxenv }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to be having trouble with this line.

I am trying this out on the dkist repo: DKISTDC/dkist#471 and by default tox puts .coverage in the .tmp/py312/ directory. Even if I move the .coverage file up into the root repo directory this still doesn't seem to find it.

Should this in fact be this:

Suggested change
run: mv $(find ~ -name .coverage) .coverage.${{ github.sha }}-${{ runner.os }}-${{ runner.arch }}-${{ matrix.toxenv }}
run: mv $(find . -name .coverage) .coverage.${{ github.sha }}-${{ runner.os }}-${{ runner.arch }}-${{ matrix.toxenv }}

i.e. look in the current directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good catch, it should be using the working directory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I can't figure out is if there's an way of doing the equivalent of this:

            rf"--cov-report=xml:${{GITHUB_WORKSPACE}}{sep}coverage.xml ")

Where we can set the .coverage path?

Copy link
Contributor Author

@zacharyburnett zacharyburnett Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coverage makes a .coverage database by default, if you don't specify a --cov-report type. I don't think you can set a location for .coverage though. You CAN specify --cov-report= to be html xml json lcov annotate (see https://pytest-cov.readthedocs.io/en/latest/reporting.html), but as far as I can tell the markdown table generator (python -Im coverage report -i -m --format=markdown) can only ingest the .coverage database so another format report is not needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's the inability to specify the path of the coverage db that seems to be a problem.

Even with the last commit I don't seem to be finding the db file: https://github.com/DKISTDC/dkist/actions/runs/12161554758/job/33916444661?pr=471#step:14:1

Testing this out locally seems to work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope you don't mind, but I pushed a couple of experimental commits to make it search from the root workspace dir down. Let's see what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok well the plot thickens: https://github.com/DKISTDC/dkist/actions/runs/12161554758/job/33918322027#step:14:1

The find command finds the file, but then it fails to upload?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! Maybe add an ls in there to see if the mv command actually worked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to go a different way and let the upload action figure it out: https://github.com/DKISTDC/dkist/actions/runs/12161554758/job/33921111684#step:14:16

It did not go well.

.github/workflows/tox.yml Outdated Show resolved Hide resolved
.github/workflows/tox.yml Outdated Show resolved Hide resolved
.github/workflows/tox.yml Outdated Show resolved Hide resolved
.github/workflows/tox.yml Outdated Show resolved Hide resolved
.github/workflows/tox.yml Outdated Show resolved Hide resolved
@Cadair
Copy link
Member

Cadair commented Dec 5, 2024

pre-commit.ci autofix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for doing code coverage reporting entirely on GitHub
3 participants