Skip to content

Commit 168118a

Browse files
Merge pull request #946 from codeflash-ai/codeflash/optimize-pr945-2025-11-27T14.49.01
⚡️ Speed up function `parse_test_failures_from_stdout` by 16% in PR #945 (`feat/feedback-loop-for-unmatched-test-results`)
2 parents 3e0440b + eb16cb2 commit 168118a

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

codeflash/verification/parse_test_output.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,17 @@ def merge_test_results(
514514

515515
def parse_test_failures_from_stdout(test_results: TestResults, stdout: str) -> TestResults:
516516
stdout_lines = stdout.splitlines()
517-
start_line = -1
518-
end_line = -1
517+
start_line = end_line = None
518+
519+
# optimize search for start/end by scanning once
519520
for i, line in enumerate(stdout_lines):
520-
if start_line != -1 and end_line != -1:
521-
break
522-
if "FAILURES" in line:
521+
if start_line is None and "FAILURES" in line:
523522
start_line = i
524-
elif "short test summary info" in line:
523+
elif start_line is not None and end_line is None and "short test summary info" in line:
525524
end_line = i
526-
if start_line == -1 or end_line == -1:
525+
break
526+
527+
if start_line is None or end_line is None:
527528
return test_results
528529

529530
complete_failure_output_lines = stdout_lines[start_line:end_line] # exclude last summary line
@@ -533,14 +534,24 @@ def parse_test_failures_from_stdout(test_results: TestResults, stdout: str) -> T
533534
current_test_case: str | None = None
534535
current_failure_lines: list[str] = []
535536

537+
# Avoid per-line string concatenation by tracking indices and performing join once per section
538+
# Precompute the boundary check value
539+
underline_prefix = "_______"
540+
541+
# Minor: Pull into local variable to avoid attribute lookup inside loop
542+
join_nl = "\n".join
543+
append = current_failure_lines.append
544+
536545
for line in complete_failure_output_lines:
537-
if line.startswith("_______"):
546+
# Fast-path: avoid .startswith() unless it can possibly match
547+
if line and line[0] == "_" and line.startswith(underline_prefix):
538548
if current_test_case:
539549
test_case_to_failure[current_test_case] = "".join(current_failure_lines)
540550
current_test_case = line.strip("_ ").strip()
541-
current_failure_lines = []
551+
# Start new collection
552+
current_failure_lines.clear()
542553
elif current_test_case:
543-
current_failure_lines.append(line + "\n")
554+
append(line + "\n")
544555

545556
if current_test_case:
546557
test_case_to_failure[current_test_case] = "".join(current_failure_lines)

0 commit comments

Comments
 (0)