def create_failed_tests_by_suite_ordered(consolidated_data):
    """Group failed tests by test suite, ordered by success rate (ascending)."""
    # Sort test suites by success rate (ascending - least successful first)
    sorted_suites = sorted(
        consolidated_data["test_suites"].items(),
        key=lambda x: (x[1]["stats"]["passed"] / x[1]["stats"]["tests"] * 100) if x[1]["stats"]["tests"] > 0 else 0,
        reverse=False,
    )

    failed_suite_tests = []

    # Process suites in order of success rate
    for suite_name, suite_data in sorted_suites:
        if suite_data["stats"]["failed"] > 0:
            suite_failures = []

            for failure in suite_data.get("failures", []):
                test_name = failure["test"]

                # Try to reconstruct full path if partial
                if "::" in test_name and "/" in test_name:
                    full_test_name = test_name
                elif "::" in test_name or "." in test_name:
                    if "/" not in test_name and suite_name not in test_name:
                        full_test_name = f"{suite_name}::{test_name}"
                    else:
                        full_test_name = test_name
                else:
                    full_test_name = f"{suite_name}::{test_name}"

                suite_failures.append(full_test_name)

            # Sort and deduplicate tests within the suite
            suite_failures = sorted(set(suite_failures))

            if suite_failures:
                failed_suite_tests.append(
                    {
                        "suite_name": suite_name,
                        "tests": suite_failures,
                        "success_rate": (suite_data["stats"]["passed"] / suite_data["stats"]["tests"] * 100)
                        if suite_data["stats"]["tests"] > 0
                        else 0,
                    }
                )

    return failed_suite_tests
Group failed tests by test suite, ordered by success rate (ascending).
utils/consolidated_test_report.py