(args)
| 722 | |
| 723 | |
| 724 | def main(args): |
| 725 | # Make sure reports directory exists |
| 726 | if not os.path.isdir(args.reports_dir): |
| 727 | print(f"Error: Reports directory '{args.reports_dir}' does not exist.") |
| 728 | return |
| 729 | |
| 730 | # Consolidate reports |
| 731 | consolidated_data = consolidate_reports(args.reports_dir) |
| 732 | |
| 733 | # Check if we found any test results |
| 734 | if consolidated_data["total_stats"]["tests"] == 0: |
| 735 | print(f"Warning: No test results found in '{args.reports_dir}' or its subdirectories.") |
| 736 | |
| 737 | # Generate markdown report |
| 738 | report = generate_report(consolidated_data) |
| 739 | |
| 740 | # Save report to file if specified |
| 741 | if args.output_file: |
| 742 | # Create parent directories if they don't exist |
| 743 | output_dir = os.path.dirname(args.output_file) |
| 744 | if output_dir and not os.path.exists(output_dir): |
| 745 | os.makedirs(output_dir) |
| 746 | |
| 747 | with open(args.output_file, "w") as f: |
| 748 | f.write(report) |
| 749 | |
| 750 | # Only print the report when saving to file |
| 751 | print(report) |
| 752 | |
| 753 | # Send to Slack if token is available (optional, can be disabled) |
| 754 | slack_token = os.environ.get("SLACK_API_TOKEN") |
| 755 | if slack_token and args.slack_channel_name: |
| 756 | payload = create_slack_payload(consolidated_data) |
| 757 | |
| 758 | try: |
| 759 | client = WebClient(token=slack_token) |
| 760 | # Send main message |
| 761 | response = client.chat_postMessage(channel=f"#{args.slack_channel_name}", blocks=payload) |
| 762 | print(f"Report sent to Slack channel: {args.slack_channel_name}") |
| 763 | |
| 764 | # Send failed tests as separate threaded replies grouped by test suite (ordered by success rate) |
| 765 | total = consolidated_data["total_stats"] |
| 766 | if total["failed"] > 0: |
| 767 | failed_suites = create_failed_tests_by_suite_ordered(consolidated_data) |
| 768 | for suite_info in failed_suites: |
| 769 | suite_name = suite_info["suite_name"] |
| 770 | suite_tests = suite_info["tests"] |
| 771 | success_rate = suite_info["success_rate"] |
| 772 | message_text = ( |
| 773 | f"**{suite_name}** (Success Rate: {success_rate:.2f}%)\n```\n" |
| 774 | + "\n".join(suite_tests) |
| 775 | + "\n```" |
| 776 | ) |
| 777 | client.chat_postMessage( |
| 778 | channel=f"#{args.slack_channel_name}", |
| 779 | thread_ts=response["ts"], # Reply in thread |
| 780 | text=message_text, # Use text instead of blocks for markdown |
| 781 | ) |
no test coverage detected
searching dependent graphs…