Other applications can read this XML just fine but in Sonar I get an error:
The following error(s) occurred while trying to import coverage report:
Invalid directory path in 'source' element: src%nCannot resolve the file path 'clients.py' of the coverage report, the file does not exist in all 'source'.%nCannot resolve 15 file paths, ignoring coverage measures for those files
Not sure what the error is saying since src is the proper path to the sources, e.g. the first file to analyze would be src/file1.py.
Okay, nothing super-obvious is jumping out at me here. And yet…
First, there’s no need for the double-specification of sonar.test.inclusions and sonar.tests when they describe the same set. And since the test files are a subset of sonar.sources, they should be excluded. So, can you adjust that to this:
Specifically this seems to be the issue that gives me a 0% coverage report in Sonar:
INFO: Parsing report '/github/workspace/main-repo/test-reports/coverage/coverage.xml'
WARN: Invalid directory path in 'source' element: src
ERROR: Cannot resolve the file path 'clients.py' of the coverage report, the file does not exist in all 'source'.
ERROR: Cannot resolve 17 file paths, ignoring coverage measures for those files
Thanks for the log. As you know, you had already excerpted the relevant pieces, but having the whole thing helps me make sure I haven’t missed anything,
So… Let’s go back to that error:
WARN: Invalid directory path in 'source' element: src
ERROR: Cannot resolve the file path 'clients.py' of the coverage report, the file does not exist in all 'source'.
ERROR: Cannot resolve 17 file paths, ignoring coverage measures for those files
I think that’s how analysis is reading it to. But I think analysis is already in the src directory because that’s where sonar.sources is set to. So the structure that’s expected ends up being
Which, of course, doesn’t exist.
Can you try this without that <source>src</source> element?
Sonar is perfectly happy with this and I read this as meaning ./src/clients.py - unless sonar is just ignoring the package name?
Also, using the include directive instead of the source directive means that files that are not analyzed but that are still source files don’t show up in the coverage report - from the documentation: Specifying source files — Coverage.py 7.6.4 documentation
If the source option is specified, only code in those locations will be measured. Specifying the source option also enables coverage.py to report on un-executed files, since it can search the source tree for files that haven’t been measured at all.
While Sonar does pick up unexecuted files in its final reporting, it makes it harder to harmonize the number in the report from the number in Sonar post-build (it also doesn’t reflect the Sonar documentation on how to set up coverage).