Skip to content

Upload JUnit Test Reports to Codecov for Enhanced Test Visibility #13363

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

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

Conversation

BahramF73
Copy link
Contributor

Description

Upload JUnit test reports to Codecov to enable test result visibility in the Codecov UI.

Checklist

  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the
  • Create a new changelog file in the changelog folder, with a name 12689.improvement.rst.

Changelog

Added a new changelog entry: changelog/12689.improvement.rst.

Additional Notes

This PR does not fix any specific issue but improves the integration with Codecov by uploading JUnit test reports.

Closes #12689

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Apr 8, 2025
if: "matrix.use_coverage"
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: false
files: ./coverage.xml
files: ./coverage.xml,./report.xml
Copy link
Member

@nicoddemus nicoddemus Apr 10, 2025

Choose a reason for hiding this comment

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

Thanks @BahramF73!

According to https://github.com/codecov/codecov-action, there is also report_type:

The type of file to upload, coverage by default. Possible values are "test_results", "coverage".

Do we need to set that as well, or does code-cov detect the types of file automatically? I could not find any information regarding that on a quick search over the docs (but likely I missed something).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this and I added report_type.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

LGTM, let's see how it fares once it is in production.

Will leave it open for a few days to give others a chance to review.

@BahramF73
Copy link
Contributor Author

LGTM, let's see how it fares once it is in production.

Will leave it open for a few days to give others a chance to review.

Awesome, yeah, let’s see how it goes!

@@ -268,6 +268,15 @@ jobs:
files: ./coverage.xml
verbose: true

- name: Upload test results to Codecov
if: "matrix.use_coverage"
uses: codecov/codecov-action@v5
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this works? The docs you've linked mention codecovcli do-upload --report-type test_results under Set up by directly using the CLI, but under Set up using the action they suggest a dedicated codecov/test-results-action@v1 action, including a suggestion to use if: ${{ !cancelled() }} with it. Why not follow that?

Copy link
Member

Choose a reason for hiding this comment

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

You're right. That action is what must be used. I just run one after the other in my projects: https://github.com/tox-dev/workflow/blob/89de3c6/.github/workflows/reusable-tox.yml#L422-L469.

tox.ini Outdated
@@ -62,6 +62,7 @@ setenv =
coverage: _PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess
coverage: COVERAGE_FILE={toxinidir}/.coverage
coverage: COVERAGE_PROCESS_START={toxinidir}/.coveragerc
coverage: PYTEST_ADDOPTS=--junitxml=report.xml
Copy link
Member

Choose a reason for hiding this comment

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

The docs say:

Include the optional junit_family flag to have pretty-printed test names in the Codecov UI.

Copy link
Member

Choose a reason for hiding this comment

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

I'd recommend trying to integrate this in CI only since local runs don't normally need XML files.

@@ -0,0 +1 @@
Upload JUnit test reports to Codecov to enable test result visibility in the Codecov UI.
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's confusing to have this as an improvement changelog entry, as that's user-facing improvements. I think contrib would fit much better.

…uration in CI workflow

Rename improvement documentation and update test result upload configuration in CI workflow
@BahramF73 BahramF73 requested a review from The-Compiler April 11, 2025 10:45
tox.ini Outdated
@@ -62,6 +62,7 @@ setenv =
coverage: _PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess
coverage: COVERAGE_FILE={toxinidir}/.coverage
coverage: COVERAGE_PROCESS_START={toxinidir}/.coveragerc
coverage: PYTEST_ADDOPTS=--junitxml=junit.xml -o junit_family=legacy
Copy link
Member

Choose a reason for hiding this comment

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

JUnit isn't coverage, though... Also, is it possible to use long option names?

P.S. It'd be good not to generate this in local runs, but only CI.

Copy link
Member

Choose a reason for hiding this comment

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

It'd be good not to generate this in local runs, but only CI.

TBH I wouldn't care too much... we need however to add junit.xml to .gitignore. However, if it is simple to not generate this for local runs, we can go ahead, but I wouldn't complicate things too much if not.

Copy link
Member

Choose a reason for hiding this comment

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

Fair. In my CIs, I have built-in ways of having this separation. Perhaps, one day I'll get to refactoring this one as well...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TODO] Upload JUnit reports to Codecov
4 participants