cookiecutter-scverse icon indicating copy to clipboard operation
cookiecutter-scverse copied to clipboard

fix codecov upload (closes #381)

Open ilia-kats opened this issue 8 months ago • 1 comments

The codecov action can generate a usable report itself, but it needs the coverage package installed and accessible. This is not the case anymore, since it's now only installed in the hatch test environment. So we generate the report ourselves.

ilia-kats avatar Apr 04 '25 11:04 ilia-kats

Thanks @ilia-kats. We thought that hatch test --cover already creates the coverage report, but that doesn't seem to be the case.

Your solution will certainly work, I'm just wondering if it would be even better to somehow include this in the hatch script definition in pyproject.toml? @flying-sheep you get to decide.

grst avatar Apr 05 '25 20:04 grst

OK so first of all, Ilan and I have seen some issues with letting codecov run coverage xml, so doing that ourselves is probably best: https://github.com/codecov/codecov-cli/issues/648

Then generating the XML isn’t really necessary for any tool we use, so generating it locally would work, but just generate a useless file in the project root for most people. Also it’s only possible to override all of an environment’s scripts at once, so we’d have to add all of this to the config (see defaults):

[tool.hatch.envs.hatch-test.scripts]
run = "pytest{env:HATCH_TEST_ARGS:} {args}"
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
cov-combine = [ "coverage combine", "coverage xml" ] # we just want to override this …
cov-report = "coverage report"

So running it manually in CI probably best, but we need to be careful not to run into the same issue that codecov runs into: We should make sure to run coverage xml from the hatch environment, not some one-shot one that might fail to read our config or import our project properly or something.


So I say we run it using something like hatch run hatch-test.py${{ matrix.python }}:coverage xml (didn’t test that, might have gotten the syntax slightly wrong)

flying-sheep avatar Apr 07 '25 08:04 flying-sheep

@ilia-kats, can you confirm

hatch run hatch-test.py${{ matrix.python }}:coverage xml

works for you?

grst avatar Apr 07 '25 09:04 grst

It needs to be uvx hatch run .... That works.

ilia-kats avatar Apr 07 '25 11:04 ilia-kats