I have a simple python project organized as follows:
src
app.py
fizzbuzz.py
test
fizzbuzz_test.py
But it seems that sonar.sources
is not working properly because SonarQube is considering tests file part of the coverage.
I’ve tried several configurations:
1. Simple config
sonar.sources=src
sonar.tests=test
but I got this error:
ERROR: Error during SonarScanner execution
ERROR: File test/fizzbuzz_test.py can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
2. Complex test inclusion
sonar.sources=src
sonar.tests.inclusions=test/**/*_test.py
that pass indexing
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: .vscode, conftest.py
INFO: 10 files indexed... (last one was .pylintrc)
INFO: 10 files indexed... (last one was .pylintrc)
INFO: 32 files indexed
INFO: 1 file ignored because of inclusion/exclusion patterns
but tests files are indexed as code that SonarQube want to cover.
I’m scanning it with:
- SonarQube: 9.5.0.56709
- SonarScanner 4.7.0.2747
With this config:
sonar.sources=src/app.py
sonar.tests.inclusions=test/**/*_test.py
# Goal: i want to delete this line
# sonar.coverage.exclusions=test/**/*, docs/**/*
sonar.exclusions=.vscode, conftest.py
sonar.language=py
sonar.python.version=3.9
sonar.sourceEncoding=UTF-8
# Unit tests
sonar.python.xunit.reportPath=build/reports/tests/*.xml
sonar.python.coverage.reportPaths=build/reports/coverage/*.xml
What I’m missing to proper configure src files ?