CircleCI Pipeline
Add the following job to your.circleci/config.yml
. It triggers on pushes to the configured branches:
-m module_name
to the upload script. You can upload multiple coverage files using multiple -m
flags.
Environment Variables Configuration
Add your access token to CircleCI:- Go to Project Settings -> Environment Variables
- Click Add Environment Variable
- Add variable name:
ACCESS_TOKEN
- Paste your GitHub access token as the value
- Click Add Environment Variable
- Go to Organization Settings -> Contexts
- Create a context named
codeant-context
- Add the
ACCESS_TOKEN
variable with your GitHub access token
Token Permissions
The access token requires the following permissions:- Metadata: Read-only access
- Commit statuses: Read and write access
Coverage config file
You have to create a.coveragerc
file in the project’s root folder to include all the source files in the test coverage calculation.
Example:
How it works
With the above configuration:coverage run -m pytest tests/
will count every .py under the workspace as “valid” lines except for those in the omitted directories.- Lines actually executed by your tests are marked “covered.”
coverage xml -o coverage.xml
produces a Cobertura-style report reflecting true coverage over the entire codebase.- Using this coverage xml, we calculate the coverage percentage and the status check will be done on every new push to the branch.
Troubleshooting
Coverage file not found
If the coverage file is not generated:- Verify tests are running successfully
- Check that coverage is installed:
pip install coverage
- Ensure the correct test command is used
- Check the working directory
Upload fails with authentication error
If you see “Access token invalid”:- Verify the
ACCESS_TOKEN
environment variable is correctly configured - Ensure the token has the required permissions
- Check that you’re using the correct context or project environment variables
Coverage percentage is 0%
If coverage shows 0%:- Check your
.coveragerc
configuration - Verify the source paths are correct
- Ensure tests are actually exercising the code
- Check omit patterns aren’t excluding too much
Branch name extraction issues
CircleCI automatically provides:CIRCLE_BRANCH
: The branch nameCIRCLE_SHA1
: The commit SHACIRCLE_PROJECT_USERNAME
: The organization/usernameCIRCLE_PROJECT_REPONAME
: The repository name