@@ -131,53 +131,64 @@ def get_broken_tests_rules(broken_tests_file_path: str) -> dict:
131131def test_is_known_fail (test_name , test_logs , build_flags , broken_tests_file_path ):
132132 matching_rules = []
133133
134- known_broken_tests = get_broken_tests_rules (broken_tests_file_path )
135-
136- # print(f"Checking known broken tests for failed test: {test_name}")
137- # print("Potential matching rules:")
138- exact_rule = known_broken_tests ["exact" ].get (test_name )
139- if exact_rule :
140- # print(f"{test_name} - {exact_rule}")
141- matching_rules .append (exact_rule )
142-
143- for name_re , data in known_broken_tests ["pattern" ].items ():
144- if name_re .fullmatch (test_name ):
145- # print(f"{name_re} - {data}")
146- matching_rules .append (data )
147-
148- if not matching_rules :
149- return False
150-
151134 def matches_substring (substring , log , is_regex ):
152135 if log is None :
153136 return False
154137 if is_regex :
155138 return bool (substring .search (log ))
156139 return substring in log
157140
158- for rule_data in matching_rules :
159- if rule_data .get ("check_types" ) and not any (
160- ct in build_flags for ct in rule_data ["check_types" ]
161- ):
162- # print(
163- # f"Check types didn't match: '{rule_data['check_types']}' not in '{build_flags}'"
164- # )
165- continue # check_types didn't match → skip rule
166-
167- is_regex = rule_data .get ("regex" , False )
168- not_message = rule_data .get ("not_message" )
169- if not_message and matches_substring (not_message , test_logs , is_regex ):
170- # print(f"Skip rule: Not message matched: '{rule_data['not_message']}'")
171- continue # not_message matched → skip rule
172- message = rule_data .get ("message" )
173- if message and not matches_substring (message , test_logs , is_regex ):
174- # print(f"Skip rule: Message didn't match: '{rule_data['message']}'")
175- continue
141+ broken_tests_log = "ci/tmp/broken_tests_handler.log"
142+
143+ with open (broken_tests_log , "a" ) as log_file :
144+ try :
145+ known_broken_tests = get_broken_tests_rules (broken_tests_file_path )
146+ except Exception as e :
147+ log_file .write (f"Error getting broken tests rules: { e } \n " )
148+ return False
176149
177- # print(f"Test {test_name} matched rule: {rule_data}")
178- return rule_data ["reason" ]
150+ log_file .write (f"Checking known broken tests for failed test: { test_name } \n " )
151+ log_file .write ("Potential matching rules:\n " )
152+ exact_rule = known_broken_tests ["exact" ].get (test_name )
153+ if exact_rule :
154+ log_file .write (f"{ test_name } - { exact_rule } \n " )
155+ matching_rules .append (exact_rule )
179156
180- return False
157+ for name_re , data in known_broken_tests ["pattern" ].items ():
158+ if name_re .fullmatch (test_name ):
159+ log_file .write (f"{ name_re } - { data } \n " )
160+ matching_rules .append (data )
161+
162+ if not matching_rules :
163+ return False
164+
165+ for rule_data in matching_rules :
166+ if rule_data .get ("check_types" ) and not any (
167+ ct in build_flags for ct in rule_data ["check_types" ]
168+ ):
169+ log_file .write (
170+ f"Check types didn't match: '{ rule_data ['check_types' ]} ' not in '{ build_flags } '\n "
171+ )
172+ continue # check_types didn't match → skip rule
173+
174+ is_regex = rule_data .get ("regex" , False )
175+ not_message = rule_data .get ("not_message" )
176+ if not_message and matches_substring (not_message , test_logs , is_regex ):
177+ log_file .write (
178+ f"Skip rule: Not message matched: '{ rule_data ['not_message' ]} '\n "
179+ )
180+ continue # not_message matched → skip rule
181+ message = rule_data .get ("message" )
182+ if message and not matches_substring (message , test_logs , is_regex ):
183+ log_file .write (
184+ f"Skip rule: Message didn't match: '{ rule_data ['message' ]} '\n "
185+ )
186+ continue
187+
188+ log_file .write (f"Test { test_name } matched rule: { rule_data } \n " )
189+ return rule_data ["reason" ]
190+
191+ return False
181192
182193
183194class SharedEngineReplacer :
@@ -2332,8 +2343,8 @@ class TestCase:
23322343 result .status = TestStatus .BROKEN
23332344
23342345 # Place the message on the second line
2335- result .description .replace (
2336- "\n " , f"\n Marked as broken: { known_fail_reason } \n " , count = 1
2346+ result .description = result . description .replace (
2347+ "\n " , f"\n Marked as broken: { known_fail_reason } \n " , 1
23372348 )
23382349
23392350 if self .name in suite .blacklist_check :
0 commit comments