Ignoring Decorator in Python Code

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension) :-
    v2025.1
  • how is SonarQube deployed: zip, Docker, Helm:- ZIP
  • what are you trying to achieve:- We have a quality gate on new code must have 70% coverage. We have few python code file which has decorators. When we run the analysis the scanner is expecting us to write down unit for those lines as well. How we can ignore such code which does not need coverage from scanning report.
    *** Is there any way in UI we can define this coverage is fine and ignored for future analysis. Also we do this will it be stayed as defined even if we upgrade sonar qube in future**.
  • what have you tried so far to achieve this:-

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi,

While you can ignore whole files for coverage, there’s no way to selectively ignore sub-sections of files.

Probably, your best bet is to downgrade your coverage target.

 
Ann

Hello @sunil.bindra,

SonarQube doesn’t actually compute code coverage, it merely imports the report from your code coverage tool. If there is an issue with how coverage is computed with decorators, we won’t be able to help.

However, as mentioned by Ann, you may use sonar.coverage.exclusions to exclude specific files from code coverage if you need.

Hope that helps,
Guillaume