Generate a comprehensive markdown report from consolidated data.
(consolidated_data)
| 348 | |
| 349 | |
| 350 | def generate_report(consolidated_data): |
| 351 | """Generate a comprehensive markdown report from consolidated data.""" |
| 352 | report = [] |
| 353 | |
| 354 | # Add report header |
| 355 | report.append("# Diffusers Nightly Test Report") |
| 356 | report.append(f"Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") |
| 357 | |
| 358 | # Removed comparison section |
| 359 | |
| 360 | # Add summary section |
| 361 | total = consolidated_data["total_stats"] |
| 362 | report.append("## Summary") |
| 363 | |
| 364 | # Get duration stats if available |
| 365 | duration_stats = consolidated_data.get("duration_stats", {}) |
| 366 | total_duration = duration_stats.get("total_duration", 0) |
| 367 | |
| 368 | summary_table = [ |
| 369 | ["Total Tests", total["tests"]], |
| 370 | ["Passed", total["passed"]], |
| 371 | ["Failed", total["failed"]], |
| 372 | ["Skipped", total["skipped"]], |
| 373 | ["Success Rate", f"{(total['passed'] / total['tests'] * 100):.2f}%" if total["tests"] > 0 else "N/A"], |
| 374 | ["Total Duration", f"{total_duration:.2f}s" if total_duration else "N/A"], |
| 375 | ] |
| 376 | |
| 377 | report.append(tabulate(summary_table, tablefmt="pipe")) |
| 378 | report.append("") |
| 379 | |
| 380 | # Removed duration distribution section |
| 381 | |
| 382 | # Add test suites summary |
| 383 | report.append("## Test Suites") |
| 384 | |
| 385 | # Include duration in test suites table if available |
| 386 | suite_durations = consolidated_data.get("duration_stats", {}).get("suite_durations", {}) |
| 387 | |
| 388 | if suite_durations: |
| 389 | suites_table = [["Test Suite", "Tests", "Passed", "Failed", "Skipped", "Success Rate", "Duration (s)"]] |
| 390 | else: |
| 391 | suites_table = [["Test Suite", "Tests", "Passed", "Failed", "Skipped", "Success Rate"]] |
| 392 | |
| 393 | # Sort test suites by success rate (ascending - least successful first) |
| 394 | sorted_suites = sorted( |
| 395 | consolidated_data["test_suites"].items(), |
| 396 | key=lambda x: (x[1]["stats"]["passed"] / x[1]["stats"]["tests"] * 100) if x[1]["stats"]["tests"] > 0 else 0, |
| 397 | reverse=False, |
| 398 | ) |
| 399 | |
| 400 | for suite_name, suite_data in sorted_suites: |
| 401 | stats = suite_data["stats"] |
| 402 | success_rate = f"{(stats['passed'] / stats['tests'] * 100):.2f}%" if stats["tests"] > 0 else "N/A" |
| 403 | |
| 404 | if suite_durations: |
| 405 | duration = suite_durations.get(suite_name, 0) |
| 406 | suites_table.append( |
| 407 | [ |