Skip to content

Commit 633ff7c

Browse files
authored
fix: fix reporting message (#760)
- Missing `len` when displaying number of success spans - Replace `click.echo("")` by an explicit `os.linesep`
1 parent db2c707 commit 633ff7c

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

mergify_cli/ci/cli.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23

34
import click
@@ -243,11 +244,13 @@ async def _process_junit_files( # noqa: PLR0913
243244
if span.status.status_code == opentelemetry.trace.StatusCode.ERROR
244245
],
245246
)
246-
nb_success_spans = [
247-
span
248-
for span in tests_cases
249-
if span.status.status_code == opentelemetry.trace.StatusCode.OK
250-
]
247+
nb_success_spans = len(
248+
[
249+
span
250+
for span in tests_cases
251+
if span.status.status_code == opentelemetry.trace.StatusCode.OK
252+
],
253+
)
251254
click.echo(
252255
f"🧪 Parsed tests: {len(tests_cases)} (✅ passed: {nb_success_spans} | ❌ failed: {nb_failing_spans})",
253256
)
@@ -295,14 +298,13 @@ async def _process_junit_files( # noqa: PLR0913
295298
err=True,
296299
)
297300

298-
click.echo("")
299301
if quarantine_exit_error_code == 0:
300-
click.echo("🎉 Verdict")
302+
click.echo(f"{os.linesep}🎉 Verdict")
301303
click.echo(
302304
f"• Status: ✅ OK — all {nb_failing_spans} failures are quarantined (ignored for CI status)",
303305
)
304306
else:
305-
click.echo("❌ Verdict")
307+
click.echo(f"{os.linesep}❌ Verdict")
306308
click.echo(
307309
f"• Status: 🔴 FAIL — {failing_tests_not_quarantined_count} unquarantined failures detected ({nb_failing_spans - failing_tests_not_quarantined_count} quarantined)",
308310
)

mergify_cli/ci/quarantine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses
2+
import os
23
import typing
34

45
import click
@@ -37,8 +38,7 @@ async def check_and_update_failing_spans(
3738
Returns the number of failing tests that are not quarantined.
3839
"""
3940

40-
click.echo("")
41-
click.echo("🛡️ Quarantine")
41+
click.echo(f"{os.linesep}🛡️ Quarantine")
4242

4343
failing_spans = [
4444
span

mergify_cli/tests/ci/test_cli.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import anys
55
import click
66
from click import testing
7+
from opentelemetry.sdk.trace import id_generator
78
import pytest
89

910
from mergify_cli.ci import cli as cli_junit_upload
@@ -310,3 +311,46 @@ def test_junit_file_not_found_error_message() -> None:
310311
assert (
311312
"check if your test execution step completed successfully" in result.output
312313
)
314+
315+
316+
async def test_process_junit_file_reporting(
317+
capsys: pytest.CaptureFixture[str],
318+
) -> None:
319+
with (
320+
mock.patch.object(
321+
quarantine,
322+
"check_and_update_failing_spans",
323+
return_value=0,
324+
),
325+
mock.patch.object(upload, "upload"),
326+
mock.patch.object(
327+
id_generator.RandomIdGenerator,
328+
"generate_span_id",
329+
return_value=12345678910,
330+
),
331+
pytest.raises(SystemExit),
332+
):
333+
await cli_junit_upload._process_junit_files(
334+
api_url="https://api.mergify.com",
335+
token="foobar", # noqa: S106
336+
repository="foo/bar",
337+
test_framework=None,
338+
test_language=None,
339+
tests_target_branch="main",
340+
files=(str(REPORT_XML),),
341+
)
342+
343+
captured = capsys.readouterr()
344+
assert (
345+
captured.out
346+
== """🚀 CI Insights · Upload JUnit
347+
────────────────────────────
348+
📂 Discovered reports: 1
349+
🛠️ MERGIFY_TEST_RUN_ID=00000002dfdc1c3e
350+
🧪 Parsed tests: 2 (✅ passed: 1 | ❌ failed: 1)
351+
352+
🎉 Verdict
353+
• Status: ✅ OK — all 1 failures are quarantined (ignored for CI status)
354+
• Exit code: 0
355+
"""
356+
)

0 commit comments

Comments
 (0)