With Test Result Ingestion, Codecov can report on any failed test runs that could impact coverage. Here's how to set this up.
- You're already set up with Codecov and are using the Codecov CLI to upload coverage reports to Codecov. Not doing this currently? Here's how to get set up with the Codecov CLI
- You're set up with a
- You're using a test runner that supports test results output in JUnit.
Here's an example using
pip install codecov-cli
The CLI also offered as binaries compatible with other operating systems. For instructions, visit this page
Codecov will need the output of your test run. If you’re building on Python, simply do the following when you’re calling
pytest in your CI.
pytest <other_args> --junitxml=<report_name>.junit.xml
pytest --cov --junitxml=testreport.junit.xml // example
The above snippet instructs
pytest to collect the result of all tests that are executed in this run and store as
<report_name>.junit.xml. Be sure to replace
<report_name> with your own filename
The following snippet instructs the CLI to to upload this report to Codecov.
codecovcli do-upload --report-type test_results --file <report_name>.junit.xml
Be sure to specify
test_results and include the file you created in Step 2. This will not necessarily upload coverage reports to Codecov.
Codecov offers existing wrappers for the CLI (Github Actions, Circle CI Orb, Bitrise Step) that makes uploading coverage to Codecov easy, as described here.
If you're running a different CI, you can upload coverage as follows
This is also described here.
Go ahead and merge these changes in. In the next step we'll verify if things are working correctly.
Ensure you're always uploading coverage and test results to Codecov - even if tests fail
If tests fail, your CI may stop there and not execute the rest of your workflow.
If this is the case, to make sure test results are uploaded to Codecov, you will need to add some configuration so that your CI will run the steps to upload to Codecov, even in the case of test failures.
For Github Actions, there are a couple of ways to do this:
You can inspect the workflow logs to see if the call to Codecov succeeded. Specifically you're looking for
You can open a PR that intentionally fails a test. After Codecov checks start running, you should find a PR comment that looks something like this:
- Ensure your
- Ensure your coverage file is being generated.
- Ensure your tests result file is generated correctly and is in xml.
Updated 14 days ago