简体   繁体   中英

sonarqube for python project not showing any test coverage

I installed sonarqube in my MAC machine using the docker compose given below.

version: "2"

services:
sonarqube:
image: sonarqube
ports:
  - "9000:9000"
networks:
  - sonarnet
environment:
  - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
volumes:
  - sonarqube_conf:/opt/sonarqube/conf
  - sonarqube_data:/opt/sonarqube/data
  - sonarqube_extensions:/opt/sonarqube/extensions
  - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins

  db:
image: postgres
networks:
  - sonarnet
environment:
  - POSTGRES_USER=sonar
  - POSTGRES_PASSWORD=sonar
volumes:
  - postgresql:/var/lib/postgresql
  # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
  - postgresql_data:/var/lib/postgresql/data

networks:
sonarnet:
driver: bridge

volumes:
  sonarqube_conf:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_bundled-plugins:
  postgresql:
  postgresql_data:

After which I used the command

sonar-scanner

to analyse the project using sonarqube.

在此输入图像描述

The analysis report is shown above. If you notice, the code coverage part is left blank, even though I have written some python unittest scripts. Please suggest a way so that I can get the code coverage report for my python project in sonarqube. Thanks in advance.

SonarQube doesn't calculate a code coverage. It only displays results provided by other tools.

You have to execute a tool which calculates code coverage (eg Coverage.py ) and next add analysis parameters:

  • sonar.python.coverage.reportPath - a report path of the unit test results
  • sonar.python.coverage.itReportPath - a report path of the integration test results

You can read everything on SonarQube wiki: https://docs.sonarqube.org/display/PLUG/Python+Coverage+Results+Import

You'll need a code coverage tool to analyze how much of the project's code is coverage by unit tests.

As mentioned, one of the tools is coverage .

The coverage tool can be used to generate a SonarQube-compatible XML report, which is then uploaded to SonarQube.

Once installed, run coverage xml .

In your sonar-project.properties add:

sonar.python.coverage.reportPath=coverage.xml

Remember to add the auto-generated coverage output files to .gitignore :

.coverage
coverage.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM