Failing to read test coverage report (sonarcloud, python)

I’m trying to report on test coverage using SonarCloud via AWS CodeBuild. The snippet below is in my script, and the cat successfully prints the content of the coverage report, but on the very next line sonar-scanner fails with a “No such file or directory”. Any insight into what the cause might be?

I’ve tried many variations on the path parameter with no success. The only thing I can think of is that I’ve set sonar.exclusions=**/test_results/** in the web settings since it was analyzing the report files as code. Would that also prevent the coverage plugin from reading that directory?

cat /www/repos/redshelf_project/test_results/coverage.xml
sonar-scanner \
    [clipped params] \
    -Dsonar.python.coverage.reportPaths=/www/repos/redshelf_project/test_results/coverage.xml
./sonarqube.sh: line 23: -Dsonar.python.coverage.reportPaths=/www/repos/redshelf_project/test_results/coverage.xml: No such file or directory 

Hi,

It looks like sonar.python.coverage.reportPaths accepts paths relative to base directory of the project. Try -Dsonar.python.coverage.reportPaths=test_results/coverage.xml.

Same result:

./sonarqube.sh: line 23: -Dsonar.python.coverage.reportPaths=test_results/coverage.xml: No such file or directory 

I’ve tried the full path, the relative path this way, ./test_results/coverage.xml, none of them are picking up the file. I know the script running this command has access to that file though since I’ve cat-ted it just before.

If sonar-scanner was called correctly and if the coverage file was not found by the python analyzer, you would get much more output and it would contain something like:

WARN: No report was found for sonar.python.coverage.reportPaths using pattern test_results/coverage.xml 

My guess is that there’s a problem with the script itself.
According to the message you got, it’s not test_results/coverage.xml which cannot be found, it’s the whole line 23 which is interpreted as a file path.

1 Like

That was the problem, I split the command over multiple lines and forgot the trailing slash to continue a single command. Thank you!