Sonar.sources seems ignored

I have a simple python project organized as follows:


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


but I got this error:

ERROR: Error during SonarScanner execution
ERROR: File test/ can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

2. Complex test inclusion


that pass indexing

INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: .vscode,
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:
  • SonarScanner

With this config:


# Goal: i want to delete this line
# sonar.coverage.exclusions=test/**/*, docs/**/*



# Unit tests

What I’m missing to proper configure src files ?

This config should work if your project is laid out exactly as described.

And in my tests it works just fine.

├── src
│   └──
└── test
sonar-scanner -Dsonar.sources=src -Dsonar.tests=test -Dsonar.projectKey=test -X

10:26:07.800 INFO: Indexing files...
10:26:07.801 INFO: Project configuration:
10:26:07.825 DEBUG: Average line length for src/ is 10
10:26:07.829 DEBUG: 'src/' indexed with language 'py'
10:26:07.857 DEBUG: Average line length for test/ is 10
10:26:07.857 DEBUG: 'test/' indexed as test with language 'py'
10:26:07.868 INFO: 2 files indexed

Just a shot in the dark – can you try running the scanner with analysis parameters passed on the command line (rather than a file)?

1 Like

It was a stupid issue, I spent days before writing this post trying to figure out the problem.

Thanks to your comment I have double-check the command line and I find out an option -Dsonar.sources=. that was overriding file entry. :sweat_smile:

Thanks, a lot!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.