Test Coverage
Azure DevOps
Set up Azure DevOps Pipelines workflow for coverage reporting.
Azure DevOps Pipelines Workflow
This pipeline triggers on pushes to the specified branch (e.g., pr_coverage
or main
) and performs the following steps:
- Runs tests and generates a coverage report.
- Fetches the CodeAnt AI upload script.
- Uploads the coverage XML to CodeAnt AI.
Don’t forget to add your access token. The access token should have write access to the repo.
The <module_name>
is optional. It is used to specify modules in the case of monorepo structure.
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:
When you assign source to ”.” , It checks for every python file in the root folder and its sub directories. You can omit some directories by placing them in the omit section of the file.
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.