Skip to content

Commit 02155ce

Browse files
committed
Test out what happens to sonarqubebot if no coverage included in pysonar upload
1 parent cf14cc0 commit 02155ce

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

exasol/toolbox/nox/_artifacts.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,7 @@ def _prepare_coverage_xml(session: Session, source: Path) -> None:
207207
f"{source}/*",
208208
"--fail-under=0",
209209
]
210-
output = subprocess.run(
211-
command, capture_output=True, text=True, check=False
212-
) # nosec
213-
214-
if output.returncode != 0:
215-
if output.stdout.strip() == "No data to report.":
216-
# Assuming that previous steps passed in the CI, this indicates — as
217-
# is in the case for newly created projects — that no coverage over the
218-
# `source` files was found. To allow Sonar to report, we create
219-
# a dummy file which will toss a warning but otherwise successfully execute.
220-
Path(COVERAGE_XML).touch()
221-
else:
222-
session.error(output.returncode)
210+
session.run(*command)
223211

224212

225213
def _upload_to_sonar(
@@ -229,8 +217,6 @@ def _upload_to_sonar(
229217
"pysonar",
230218
"--sonar-token",
231219
sonar_token,
232-
"--sonar-python-coverage-report-paths",
233-
COVERAGE_XML,
234220
"--sonar-python-pylint-report-path",
235221
LINT_JSON,
236222
"--sonar-python-bandit-report-paths",
@@ -240,6 +226,9 @@ def _upload_to_sonar(
240226
"--sonar-sources",
241227
config.source,
242228
]
229+
if Path("dummy").exists():
230+
command.extend(["--sonar-python-coverage-report-paths", COVERAGE_XML])
231+
243232
session.run(*command) # type: ignore
244233

245234

test/unit/nox/_artifacts_test.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,21 @@ def test_all_files(tmp_path, capsys):
308308
assert (tmp_path / f).exists()
309309

310310

311-
class TestPrepareCoverageXml:
312-
@staticmethod
313-
def test_no_coverage_file_creates_dummy():
314-
_prepare_coverage_xml(Mock(), PROJECT_CONFIG.source)
315-
316-
assert Path(COVERAGE_XML).exists()
317-
assert Path(COVERAGE_XML).read_text() == ""
318-
assert not Path(COVERAGE_FILE).exists()
319-
320-
@staticmethod
321-
def test_that_bad_coverage_file_still_raises_error(capsys):
322-
_create_coverage_file(Path(COVERAGE_FILE), COVERAGE_TABLES)
323-
session_mock = Mock()
324-
325-
_prepare_coverage_xml(session_mock, PROJECT_CONFIG.source)
326-
327-
assert Path(COVERAGE_FILE).exists()
328-
assert not Path(COVERAGE_XML).exists()
311+
# class TestPrepareCoverageXml:
312+
# @staticmethod
313+
# def test_no_coverage_file_creates_dummy():
314+
# _prepare_coverage_xml(Mock(), PROJECT_CONFIG.source)
315+
#
316+
# assert Path(COVERAGE_XML).exists()
317+
# assert Path(COVERAGE_XML).read_text() == ""
318+
# assert not Path(COVERAGE_FILE).exists()
319+
#
320+
# @staticmethod
321+
# def test_that_bad_coverage_file_still_raises_error(capsys):
322+
# _create_coverage_file(Path(COVERAGE_FILE), COVERAGE_TABLES)
323+
# session_mock = Mock()
324+
#
325+
# _prepare_coverage_xml(session_mock, PROJECT_CONFIG.source)
326+
#
327+
# assert Path(COVERAGE_FILE).exists()
328+
# assert not Path(COVERAGE_XML).exists()

0 commit comments

Comments
 (0)