Skip to content

SCANPY-171 Return code from the Scanner CLI is not propagated back through the Python process #227

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

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ from = 'src'
include = 'pysonar_scanner'

[tool.poetry.scripts]
pysonar = 'pysonar_scanner.__main__:scan'
pysonar = 'pysonar_scanner.__main__:main'

[[tool.poetry.source]]
name = 'jfrog-server'
Expand Down
4 changes: 4 additions & 0 deletions src/pysonar_scanner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
from pysonar_scanner.scannerengine import ScannerEngine, ScannerEngineProvisioner


def main():
exit(scan())


def scan():
try:
return do_scan()
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from pyfakefs import fake_filesystem_unittest as pyfakefs

from pysonar_scanner.__main__ import scan, check_version, create_jre
from pysonar_scanner.__main__ import scan, main, check_version, create_jre
from pysonar_scanner.api import SQVersion, SonarQubeApi
from pysonar_scanner.cache import Cache
from pysonar_scanner.configuration.configuration_loader import ConfigurationLoader
Expand Down Expand Up @@ -91,6 +91,12 @@ def test_scan_with_exception(self, load_mock):
exitcode = scan()
self.assertEqual(1, exitcode)

def test_main_with_exitcode_not_zero(self):
with patch("pysonar_scanner.__main__.scan", return_value=42):
with self.assertRaises(SystemExit) as main_exit:
main()
self.assertEqual(main_exit.exception.code, 42)

def test_version_check_outdated_sonarqube(self):
sq_cloud_api = sq_api_utils.get_sq_server()
sq_cloud_api.get_analysis_version = Mock(return_value=SQVersion.from_str("9.9.9"))
Expand Down