Reputation: 8570
I want to create a Github workflow that does the following:
pytest
As far as I understand, SonarQ needs a file coverage.xml
to display the code coverage. This can be generated with
pytest --cov=./ --cov-report=xml --doctest-modules
According to this article coverage.xml
should be available under /github/workspace/coverage.xml
.
Thus, I specify my sonar-project.properties
in the root folder of the project:
sonar.organization=pokemate
sonar.projectKey=PokeMate_name-generator
sonar.sources=.
sonar.python.coverage.reportPath=/github/workspace/coverage.xml
my actions file build.yml
:
on:
push:
branches:
- master
- develop
- sonar-qube-setup
jobs:
build:
runs-on:
- ubuntu-latest
steps:
# Checkout repo
- uses: actions/checkout@v2
# Dependencies
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Test
- name: Test with pytest
run: |
pytest --cov=./ --cov-report=xml --doctest-modules
# Sonar Qube
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
However, on SonarQ it still shows 0% test coverage, which is probably because it cannot find the coverage.xml
. Any idea how to make this work?
Upvotes: 2
Views: 4219
Reputation: 8570
The error came from the missing s
in reportPaths
in the sonar-project.properties
file.
Upvotes: 3