|
| 1 | +import re |
| 2 | + |
| 3 | +def parse_failed_tests(log_content): |
| 4 | + # Patterns for test names and errors |
| 5 | + test_pattern = r"_{5,}\s+(test_[\w_]+)\s+_{5,}" |
| 6 | + path_pattern = r"([\/\w-]+\.py):(\d+)" |
| 7 | + type_error_pattern = r"TypeError: An asyncio\.Future, a coroutine or an awaitable is required" |
| 8 | + |
| 9 | + failed_tests = [] |
| 10 | + current_test = None |
| 11 | + current_path = None |
| 12 | + error_context_lines = [] |
| 13 | + in_error_section = False |
| 14 | + |
| 15 | + # Split log into lines |
| 16 | + lines = log_content.split('\n') |
| 17 | + |
| 18 | + for i, line in enumerate(lines): |
| 19 | + # Look for test name |
| 20 | + test_match = re.search(test_pattern, line) |
| 21 | + if test_match: |
| 22 | + current_test = test_match.group(1) |
| 23 | + in_error_section = False |
| 24 | + error_context_lines = [] |
| 25 | + |
| 26 | + # Look for file path |
| 27 | + path_match = re.search(path_pattern, line) |
| 28 | + if path_match: |
| 29 | + current_path = path_match.group(1) |
| 30 | + |
| 31 | + # Store context lines |
| 32 | + if current_test: |
| 33 | + error_context_lines.append(line.strip()) |
| 34 | + |
| 35 | + # Check for errors |
| 36 | + if current_test and ("KeyError:" in line or re.search(type_error_pattern, line)): |
| 37 | + in_error_section = True |
| 38 | + error_type = "KeyError" if "KeyError:" in line else "TypeError" |
| 39 | + |
| 40 | + # Clean up the path |
| 41 | + if current_path: |
| 42 | + clean_path = re.search(r'(?:^|/)(?:test/.+|plenum/test/.+)$', current_path) |
| 43 | + test_path = clean_path.group(0) if clean_path else current_path |
| 44 | + test_path = test_path.lstrip('/') |
| 45 | + else: |
| 46 | + test_path = "path not found" |
| 47 | + |
| 48 | + # Get the error context (lines leading up to error) |
| 49 | + context_window = 10 # Increase context window for better visibility |
| 50 | + error_context = [] |
| 51 | + start_idx = max(0, len(error_context_lines) - context_window) |
| 52 | + for j in range(start_idx, len(error_context_lines)): |
| 53 | + if error_context_lines[j]: # Only add non-empty lines |
| 54 | + error_context.append(error_context_lines[j]) |
| 55 | + |
| 56 | + failed_tests.append({ |
| 57 | + 'test_name': current_test, |
| 58 | + 'test_path': test_path, |
| 59 | + 'error_type': error_type, |
| 60 | + 'error_line': line.strip(), |
| 61 | + 'error_context': '\n'.join(error_context) |
| 62 | + }) |
| 63 | + |
| 64 | + # Reset for next test |
| 65 | + if in_error_section and line.strip() == "" and current_test: |
| 66 | + in_error_section = False |
| 67 | + error_context_lines = [] |
| 68 | + |
| 69 | + return failed_tests |
| 70 | + |
| 71 | +def main(): |
| 72 | + try: |
| 73 | + # Read log file |
| 74 | + with open('test-result-plenum-2.txt', 'r') as f: |
| 75 | + log_content = f.read() |
| 76 | + |
| 77 | + # Get failed tests |
| 78 | + failed_tests = parse_failed_tests(log_content) |
| 79 | + |
| 80 | + # Print results |
| 81 | + if failed_tests: |
| 82 | + print(f"Found {len(failed_tests)} test failures:\n") |
| 83 | + |
| 84 | + # Group failures by error type |
| 85 | + key_errors = [t for t in failed_tests if t['error_type'] == 'KeyError'] |
| 86 | + type_errors = [t for t in failed_tests if t['error_type'] == 'TypeError'] |
| 87 | + |
| 88 | + if key_errors: |
| 89 | + print(f"KeyError Failures ({len(key_errors)}):") |
| 90 | + print("=" * 80) |
| 91 | + for i, test in enumerate(key_errors, 1): |
| 92 | + print(f"Failure #{i}:") |
| 93 | + print(f"Test Name: {test['test_name']}") |
| 94 | + print(f"Test Path: {test['test_path']}") |
| 95 | + print("Error Context:") |
| 96 | + print(test['error_context']) |
| 97 | + print("-" * 80 + "\n") |
| 98 | + |
| 99 | + if type_errors: |
| 100 | + print(f"\nTypeError Failures ({len(type_errors)}):") |
| 101 | + print("=" * 80) |
| 102 | + for i, test in enumerate(type_errors, 1): |
| 103 | + print(f"Failure #{i}:") |
| 104 | + print(f"Test Name: {test['test_name']}") |
| 105 | + print(f"Test Path: {test['test_path']}") |
| 106 | + print("Error Context:") |
| 107 | + print(test['error_context']) |
| 108 | + print("-" * 80 + "\n") |
| 109 | + |
| 110 | + else: |
| 111 | + print("No test failures found") |
| 112 | + |
| 113 | + except FileNotFoundError: |
| 114 | + print("Error: test_log.txt file not found") |
| 115 | + except Exception as e: |
| 116 | + print(f"An error occurred: {str(e)}") |
| 117 | + |
| 118 | +if __name__ == "__main__": |
| 119 | + main() |
0 commit comments