Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarQube passed ignoring test coverage threshold #905

Open
Famondir opened this issue Feb 7, 2024 · 5 comments
Open

SonarQube passed ignoring test coverage threshold #905

Famondir opened this issue Feb 7, 2024 · 5 comments

Comments

@Famondir
Copy link

Famondir commented Feb 7, 2024

Hi all,
today I set up PyBuilder with SonarQube. It works fine. But even though I have not met my test coverage threshold (neither the one stated in PyBuilder e.g. 70 % nor the standard one in SonarQube 80 %). When I just run sonar-scanner outside of the PyBuilder pipeline it notes me that the criteria are violated in SonarQube marking it as a Failure.

It would be great to communicate the threshold from PyBuilder or adjust the used quality gate somehow. Maybe this is already possible and you can tell me how?

@arcivanov
Copy link
Member

Could you please provide your build.py?

@Famondir
Copy link
Author

Famondir commented Feb 8, 2024

Sure. I tried it with this version using pytest:

#   -*- coding: utf-8 -*-
from pybuilder.core import use_plugin, init

use_plugin("python.core")
# use_plugin("python.unittest")
use_plugin('pypi:pybuilder_pytest')
use_plugin("python.flake8")
# use_plugin("python.coverage")
use_plugin('pypi:pybuilder_pytest_coverage')
use_plugin("python.distutils")
use_plugin("python.sonarqube")


name = "Music-Suite"
default_task = "publish"


@init
def set_properties(project):
    project.set_property("pytest_coverage_xml", True)
    project.get_property("pytest_extra_args").append("-x")
    project.set_property("pytest_coverage_break_build_threshold", 70)

    project.set_property("sonarqube_project_key", "musicsuitmusicsuite:2024e")
    # project.set_property("sonarqube_project_name", "Music Suite")

And using the default test suite like this:

#   -*- coding: utf-8 -*-
from pybuilder.core import use_plugin, init

use_plugin("python.core")
use_plugin("python.unittest")
# use_plugin('pypi:pybuilder_pytest')
use_plugin("python.flake8")
use_plugin("python.coverage")
# use_plugin('pypi:pybuilder_pytest_coverage')
use_plugin("python.distutils")
use_plugin("python.sonarqube")


name = "Music-Suite"
default_task = "publish"


@init
def set_properties(project):
    # project.set_property("pytest_coverage_xml", True)
    # project.get_property("pytest_extra_args").append("-x")
    # project.set_property("pytest_coverage_break_build_threshold", 70)

    project.set_property("sonarqube_project_key", "musicsuitmusicsuite:2024e")
    # project.set_property("sonarqube_project_name", "Music Suite")

@arcivanov
Copy link
Member

Well, I'm confused here. Does the coverage break without sonar cube? Because PyTest Coverage has nothing to do with SQ.

@Famondir
Copy link
Author

Famondir commented Feb 9, 2024

When I run pyb instead of pyb run_sonar_analysis then the indication of not met thresholds is printed correctly in the terminal output.

And when I run the sonar scanner manually with sonar-scanner -Dsonar.projectKey=musicsuitmusicsuite:2024e -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.token=sqp_xyz the not met threshold is violating the qualitygates correctly.

But when I run the sonar-scanner with PyBuilder it reports no quality gate issue. But I think I found the problem. After limiting the sonar-runner only on the src/main/python folder I got no issue there as well, because it only looked for new code and not the missing tests for the already existing code as it seems.

So when I added some more new code both ways report issues.

@Famondir Famondir closed this as completed Feb 9, 2024
@arcivanov arcivanov reopened this Feb 9, 2024
@arcivanov
Copy link
Member

I'll keep this open as it might be a bug, but I'll need to create a repro case for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants