Python Coverage File Not Found

  • ALM used: GitHub
  • CI system used: Github Actions
  • Scanner command used: Automatic Analysis on PR
  • Languages of the repository: Python
  • Only if the SonarCloud project is public, the URL
  • Error observed:
    • I’ve seen a few posts like this so apologies for adding another to the pile; I wasn’t able to get things working following along. My coverage.xml is being created during CI and pushed back to the branch. The file is being created and added as expected, Coverage XML written to file tests/_coverage/coverage.xml, but SonarCloud doesnt seem to find it. I’ve specified the path in the .sonarcloud.properties file with sonar.python.coverage.reportPaths=**/tests/_coverage/*.xml. I’ve tried a few combinations

Full .sonarcloud.properties

sonar.projectKey=Snayff_notquiteparadise
sonar.organization=snayff

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=notquiteparadise
#sonar.projectVersion=1.0

# Path is relative to the .sonarcloud.properties file. Replace "\" by "/" on Windows.
sonar.inclusions=**/scripts/**
sonar.exclusions=**/docs/**,**/logs/**,.mypy_cache/**,.github/**,assets/**
sonar.test.inclusions=**/tests/**
sonar.python.coverage.reportPaths=**/tests/_coverage/*.xml

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

# other
sonar.showProfiling=true
sonar.verbose=true

Any ideas or suggestions?

Hello @snayff and welcome to our community,

Unfortunately, importing coverage information is not yet supported when using automatic analysis (see current limitations in the doc: https://sonarcloud.io/documentation/analysis/automatic-analysis/).

As I see you are using Github Actions, you can however instead use the SonarCloud Github Action in your GitHub workflow to circumvent this limitation.

Hope that helps,
Guillaume

2 Likes

Ah, OK, thank you! So I have tried to use the Action but am currently finding that the directories specified in the sonar-project.properties are not found. I’ve tried setting the projectBaseDir to . as I thought that might be it.

Caused by: The folder 'tests/**' does not exist for 'Snayff_notquiteparadise' (base directory = /github/workspace)

Full log here: https://github.com/Snayff/notquiteparadise/runs/1268198805?check_suite_focus=true#step:4:243

Am I missing something?

I’ve gone back to automatic analysis and used something else for coverage.

Hello,

I’m glad you found another workaround to your problem. For the record, I’ll try to give you pointers into getting this to work entirely with SonarCloud.

In the last example, your properties settings seem a bit weird to me.
You have this error in your logs:
10:17:11.703 ERROR: Invalid value of sonar.tests for Snayff_notquiteparadise

Also I believe if you want to refer to a folder, you don’t need to add /** at its end, as the subdirectories are automatically included.

So my suggestion would be to try to replace sonar.test.inclusions=tests/** with sonar.tests=tests instead.

If you do that, when importing your code coverage, you might also encounter a problem with incorrect file paths in your coverage file, which you can fix following the advice from this thread:

Here’s a sample Python project that deals with this:

Hope that helps,
Guillaume

1 Like