On my python project, sonarQube (V 7.7) is showing 0% coverage on the class files and 100% coverage on the test files associated to the classes

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    Enterprise Edition Version 7.7 (build 23042)
  • what are you trying to achieve
    Get a proper scanning out of sonarQube
  • what have you tried so far to achieve this
    The sonarQube is called from a CICD pipeline. The cov.xml and junit-report.xml files are being generated and pushed to sonarQube

This is my sonarscan job. I have change a bit some path in the .xml file in order for Qube to work:

sonar scan:
  <<: *docker
  stage: scan
  script:
    - apk add --no-cache openssl ca-certificates curl unzip openjdk8-jre
    - apk add --update-cache --upgrade curl
    - curl -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_CLI}-linux.zip -o /opt/sonar.zip
    - unzip /opt/sonar.zip -d /opt
    - mv /opt/sonar-scanner-${SONAR_SCANNER_CLI}-linux/jre/bin/java /opt/sonar-scanner-${SONAR_SCANNER_CLI}-linux/jre/bin/java_org
    - ln -s /usr/lib/jvm/default-jvm/jre/bin/java /opt/sonar-scanner-${SONAR_SCANNER_CLI}-linux/jre/bin/java
    - export PATH="$PATH:/opt/sonar-scanner-${SONAR_SCANNER_CLI}-linux/bin"
    - sed 's/filename\=\"/filename\=\"\/builds\/core-tech\/tools\/nlu\/mix-nlu-middleware\/server\/tests\//g' ./server/cov.xml >> ./server/covu.xml
    - cp ./server/covu.xml ./server/tests/covu.xml
    - cp ./server/junit-report.xml ./server/tests/junit-report.xml
    - sonar-scanner -Dsonar.projectKey=mix-nlu-middleware -Dsonar.sources=./server -Dsonar.host.url=$SONAR_SERVER_HOST -Dsonar.login=$SONAR_LOGIN -Dsonar.python.coverage.reportPaths=server/tests/covu.xml -Dsonar.junit.reportPaths=server/tests/junit-report.xml -Dsonar.exclusions=server/bolt/core/db/migrations/versions/**,server/**/__init__.py,server/bolt/api/onse/ontology/**,server/bolt/api/routing.py
  when: manual

The xmls are generated like this:

test binaries:
  <<: *docker
  stage: test
  when: manual
  script:
    - apk add --no-cache py-pip
    - cp version.txt server/
    - pip install docker-compose==$DOCKER_COMPOSE
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker load -i image_artifacts/middleware_image.tar
    - docker tag $WEB_SERVER_IMAGE:$VERSION $WEB_SERVER_IMAGE_NAME
    - cd server/tests
    - docker-compose build
    - docker-compose run --rm initdb
    - docker-compose run --rm pytest --reruns 5 --reruns-delay 1 --cov bolt --cov tests --cov-report xml:cov.xml --junitxml=junit-report.xml
    - cd ../..
  artifacts:
    paths:
      - server/cov.xml
      - server/junit-report.xml
  allow_failure: true

The output I’m getting in the Sonar console, shows 0% coverage for the tested files and 100% coverage for the test files (check the attachment for details.). I would have expected something the other way around.
I know for sure that the coverage for server/bolt/core/db/models/channel_modes.py should be over 0% as server/tests/api/db/models/project/channel_modes_test.py covers quite a lot in channel_modes.py

Any idea what is wrong here?

Hi @doi_zece,

Can you please show the output of sonar-scanner? It would be useful to see the content of the xml file that you’re passing to sonar-scanner, i.e. server/tests/covu.xml

Beware that coverage report has to generated with coverage tool.

Have a look here to see how you can generate it: [Coverage & Test Data] Generate Reports for Apex, C/C++, Objective-C, Go, JS/TS and Python