- ALM used: GitHub
- CI system used: GitHub Actions
- Scanner command used: SonarSource/sonarcloud-github-action@master
- Languages of the repository: Python
I have a Git repo on GitHub. The repo contains a Python package. I can run tests and generate coverage.xml (Python coverage report) successfully. After that, I can use the GitHub Actions step SonarSource/sonarcloud-github-action@master
to scan coverage.xml for SonarCloud to analyze the test coverage. Everything is fine.
However, I’m planning to add another Python package into the Git repo. That means I have to move the current package into a subdirectory, and then create a new package in another subdirectory. I’m changing this:
.
├── LICENSE
├── README.md
├── src
├── setup.py
├── tests
└── tox.ini
into this:
.
├── LICENSE
├── README.md
├── package1
│ ├── src
│ ├── setup.py
│ ├── tests
│ └── tox.ini
└── package2
├── src
├── setup.py
├── tests
└── tox.ini
After moving the current package into a subdirectory, the GitHub Actions step SonarSource/sonarcloud-github-action@master
stopped working properly. The error message says:
INFO: Parsing report '/github/workspace/package1/coverage.xml'
ERROR: Cannot resolve the file path 'src/__init__.py' of the coverage report, the file does not exist in all 'source'.
ERROR: Cannot resolve 16 file paths, ignoring coverage measures for those files
The message suggests that it can find the coverage.xml file, but failed to resolve the source code files that are specified in coverage.xml.
I saw a StackOverflow question that has similar problem as mine, and there is a workaround that uses sed
to modify the coverage.xml file. The workaround did work for me, but I don’t think it’s a nice solution.
Is there a better solution for handling Python coverage reports in subdirectories? Thanks.