@@ -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
225213def _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
0 commit comments