From 6a12b43ac00096976a886bd6d3a1b70a804d09ca Mon Sep 17 00:00:00 2001 From: David Spickett Date: Mon, 18 Nov 2024 09:07:15 +0000 Subject: [PATCH] [ci] Fix error when no junit files are passed to report generator This resulted in the style being None and despite the report being empty as well, we tried to send it to the agent and Python can't send None as an argument. To fix this return "success" style and also check whether the report has any content before calling the agent. --- .ci/generate_test_report.py | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/.ci/generate_test_report.py b/.ci/generate_test_report.py index b2ab81ae4e01..237f45e6f08e 100644 --- a/.ci/generate_test_report.py +++ b/.ci/generate_test_report.py @@ -309,10 +309,8 @@ class TestReports(unittest.TestCase): # If include failures is False, total number of test will be reported but their names # and output will not be. def _generate_report(title, junit_objects, size_limit=1024 * 1024, list_failures=True): - style = None - if not junit_objects: - return ("", style) + return ("", "success") failures = {} tests_run = 0 @@ -403,22 +401,23 @@ if __name__ == "__main__": report, style = generate_report(args.title, args.junit_files) - p = subprocess.Popen( - [ - "buildkite-agent", - "annotate", - "--context", - args.context, - "--style", - style, - ], - stdin=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True, - ) + if report: + p = subprocess.Popen( + [ + "buildkite-agent", + "annotate", + "--context", + args.context, + "--style", + style, + ], + stdin=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) - # The report can be larger than the buffer for command arguments so we send - # it over stdin instead. - _, err = p.communicate(input=report) - if p.returncode: - raise RuntimeError(f"Failed to send report to buildkite-agent:\n{err}") + # The report can be larger than the buffer for command arguments so we send + # it over stdin instead. + _, err = p.communicate(input=report) + if p.returncode: + raise RuntimeError(f"Failed to send report to buildkite-agent:\n{err}")