How to check code coverage#
From the command line#
Code coverage is reported to the command line and to a cov.xml file by the
command uv run tox -e tests. The file is uploaded to the Codecov service in
CI.
To view the coverage locally in a view similar to codecov, pytest can generate html coverage info.
```sh
$ uv run tox -e tests -- --cov-report html
```
This will generate html in the htmlcov directory and opening
htmlcov/index.html in a browser will show browsable coverage information.
From VSCode#
If you are using VSCode IDE, you can also check code coverage by right-clicking
on the test icon and selecting Run with coverage. This will re-run the test
and highlight line numbers in your file:
Green = covered by tests
Red = not covered (and ideally should be tested)
Adding a Codecov Token#
If the repo is not hosted in DiamondLightSource, then you need to visit
https://app.codecov.io/account/gh/<org_name>/org-upload-token to generate a
token for your org, and store it as a secret named CODECOV_TOKEN in
https://github.com/organizations/<org_name>/settings/secrets/actions