Hello, team.
We are having an issue where the test coverage on new lines through PR decoration on Github Actions are not working as expected.
We are gettitng a different total percentages when we are running coverage run and coverage report
For example, we have a PR where we are adding code into this function, and while we run the tox -e py locally we are not getting the same amount of percentage covered as we see on the Github workflow.
Locally:
api_v2/abcd_folder/abcd_file.py 110 50 44 3 47%
Github Workflows:
api_v2/abcd_folder/abcd_file.py 110 86 44 0 16%
Here’s our build.yml
name: PR Decoration
on:
push:
branches:
- develop
- production
- pre-production
- devtestingsonar
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install tox
run: pip install tox
- name: Run tox
run: tox -e py
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
We would like to validate and see if our sonar-project.properties
are fine, find them attached:
sonar.projectKey=xxxxx
sonar.organization=xxxxxxx
sonar.python.version=3.8
sonar.exclusions=external_services/book/tests/files/**/*, **/xsd_model/**/*
sonar.test.inclusions=**/tests/**/*, **test_*.py
sonar.test.exclusions=external_services/book/tests/files/**/*, **/xsd_model/**/*
sonar.qualitygate.wait=true
sonar.python.coverage.reportPaths=coverage.xml
And this is our tox.ini
file:
[tox]
envlist = py38
skipsdist = True
[testenv]
deps =
-r requirements.txt
coverage
commands =
coverage run manage.py test --parallel
coverage xml
coverage report
[coverage:run]
relative_files = True
branch = True
source = .
omit =
external_services/book/tests/files/**/*
**/xsd_model/**/*
**/*airsub.py
[coverage:report]
omit =
external_services/book/tests/files/**/*
**/xsd_model/**/*
**/*airsub.py
We are mainly concerned on how the paramaters inside sonar-project.properties
and tox.ini
file should work. See some screenshots attached of the results from the PR decoration
Please let me know if there are any more details needed to solve this.
Thanks.
Christian.