I am experiencing a very strange error when analyzing a Python project in jenkins with sonarscanner.
In fact, after a commit where a lot of code lines has been removed, I ran a coverage scan (with python module) and when i tried to pass the report to the sonar-scanner binary plugin on to Jenkins, a java exception appeared, told me that « line XXX is out of range in file YYY ». Where XXX is part of my deleted line, and YYY is one of my source file.
Is anybody experienced the same behaviour ?
I already tried to remove .sonar cache in jenkins home and .sonarwork in my jenkins pipeline, but no effect...
Thank you in advance for your help !
Cheers !
The issue is with the coverage xml format and latest sonar cli version to analysis the XML for metrics notification. We had two choice:
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.
Sonarqube + Jenkins : python coverage report => Line out of range after deleting lines in sources