Code coverage on 0% on both old and new code


I have a python project on bitbucket and i use circleci as a CI tool, i have configured sonarscan using the proper steps and all analysis is present but my coverage is always showing 0.0%. I configured the files to point to the generated coverage.xml file, and from the sonarscan logs it seems it does find it and parses it. However no coverage is reported for both old and new code. here are details of logs below. and also screenshots.

would really appreciate the help.

Sonarscan logs below acknowledging the presence of coverage.xml

INFO: Python test coverage
INFO: Parsing report '/home/circleci/project/test-reports/coverage.xml'
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=117ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Processing report '/home/circleci/project/test-reports/coverage.xml'
INFO: Sensor PythonXUnitSensor [python] (done) | time=67ms

my file

On sonarcloud this is what is reported

from circlici config.yaml this below is my unit test job and sonarscan right below it.

- run:
          name: Pytest
          command: | 
            coverage run -m pytest -rap  --junitxml=./test-reports/coverage.xml --ignore=./testfolder/tests/ --ignore=./testfolder/tests/ --ignore=./testfolder/tests/ ./testfolder/tests/
            coverage xml -i
      - persist_to_workspace:
          root: ~/
            - project/test-reports/coverage.xml
      - store_test_results:
          path: ./test-reports
      - store_artifacts:
          path: ./test-reports

    executor: angel
      - checkout
      - attach_workspace:
          at: ~/
      - sonarcloud/scan:
          sonar_token_variable_name: SONAR_TOKEN

from circleci artifacts it can be seen that coverage is also generated and available

Maybe am missing something

Does anyone have any idea what to do here or probably what’s wrong, i really need help…

Hello @joshua_igoni,

First of all, sorry for the late answer.

It is a known issue that, if the coverage information is generated in a different environment than the one in which the analysis takes place, the analyzer might not resolve the files properly.

Can you check that the paths in your coverage.xml report match the ones of your project?

We have a ticket to make the analyzer smarter in its file resolution. In the meantime, a common workaround is to generate your coverage information setting the relative_paths option to true (more information here) or to use a sed command to manually correct the paths yourself (like describe in this StackOverflow thread).

Hope that helps,

hello @Guillaume_Dequenne ,

from my project and the setup everything seems to match up

However, I managed to fix it by doing the following;

coverage run -m pytest -rap --junitxml=./coverage.xml ./test_folder/tests/
coverage xml -o ~/project/test-reports/coverage.xml

it turns just having junitxml generate a coverage.xml file is not good enough to get the coverage results.
The second command however transforms the file into a format or way in which your analyser finds it and reads it.

I had to dig into other forms of documentation to solve the issue.

i"ll live this here incase anyone needs it.

Thanks for responding.

1 Like