sonarqubesonarscanner

Python | Error during SonarQube Scanner execution | Line 3832 is out of range in the file .py


Below are my sonar.properties file:-

sonar.projectKey=code
sonar.projectName=PROJECT
sonar.projectVersion=0.0.1
sonar.sources=code
sonar.python.coverage.reportPath=code/coverage*.xml
sonar.python.coveragePlugin=cobertura
sonar.python.xunit.reportPath=TEST*.xml
sonar.sourceEncoding=UTF-8
sonar.pli.marginLeft=2
sonar.pli.marginRight=0

Below is the command I am executing:-

$HOME/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner -Dsonar.verbose=false -Dsonar.projectKey=code -Dproject.settings=code/devops/sonar.properties -Dsonar.host.url=https://mysonar.net -Dsonar.login=$USERNAME -Dsonar.password=$PASSWORD

Error Logs:-

INFO: Python test coverage
INFO: Parsing report '/data/jenkins/workspace/master-ci/code/coverage.xml'
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 9.052s
INFO: Final Memory: 15M/397M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Line 3832 is out of range in the file code/src/driver.py (lines: 3831)
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succedeed?

Sonarqube version:- Version 7.1 (build 11001)LGPL v3Community Sonar-scanner:- 3.2.0.1227


Solution

  • 1- Add a blankspace. (at the bottom of the coverage.xml file). This worked for an old pytest tests.

    2- In another project, I updated the following packages: pytest, pytest-cov, and coverage, this to the latest version. (Worked like a charm).

    One catch here: when updating to the latest pytest version you might find methods that no longer exist for conftest.py. Eg: get_marker which can be substituted by the new get_closest_marker. Or reserved words like "request". For the latest case you can rename the method named request.