From 0dd096283925596b891164807c4339b04a0546bb Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Wed, 2 Jul 2025 00:22:26 -0700 Subject: [PATCH 1/2] try except --- codeflash/discovery/discover_unit_tests.py | 73 +++++++++++----------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/codeflash/discovery/discover_unit_tests.py b/codeflash/discovery/discover_unit_tests.py index 0e5578c57..3968b9b48 100644 --- a/codeflash/discovery/discover_unit_tests.py +++ b/codeflash/discovery/discover_unit_tests.py @@ -627,42 +627,45 @@ def process_test_files( if not definition or definition[0].type != "function": continue - - definition_obj = definition[0] - definition_path = str(definition_obj.module_path) - - project_root_str = str(project_root_path) - if ( - definition_path.startswith(project_root_str + os.sep) - and definition_obj.module_name != name.module_name - and definition_obj.full_name is not None - ): - # Pre-compute common values outside the inner loop - module_prefix = definition_obj.module_name + "." - full_name_without_module_prefix = definition_obj.full_name.replace(module_prefix, "", 1) - qualified_name_with_modules_from_root = f"{module_name_from_file_path(definition_obj.module_path, project_root_path)}.{full_name_without_module_prefix}" - - for test_func in test_functions_by_name[scope]: - if test_func.parameters is not None: - if test_framework == "pytest": - scope_test_function = f"{test_func.function_name}[{test_func.parameters}]" - else: # unittest - scope_test_function = f"{test_func.function_name}_{test_func.parameters}" - else: - scope_test_function = test_func.function_name - - function_to_test_map[qualified_name_with_modules_from_root].add( - FunctionCalledInTest( - tests_in_file=TestsInFile( - test_file=test_file, - test_class=test_func.test_class, - test_function=scope_test_function, - test_type=test_func.test_type, - ), - position=CodePosition(line_no=name.line, col_no=name.column), + try: + definition_obj = definition[0] + definition_path = str(definition_obj.module_path) + + project_root_str = str(project_root_path) + if ( + definition_path.startswith(project_root_str + os.sep) + and definition_obj.module_name != name.module_name + and definition_obj.full_name is not None + ): + # Pre-compute common values outside the inner loop + module_prefix = definition_obj.module_name + "." + full_name_without_module_prefix = definition_obj.full_name.replace(module_prefix, "", 1) + qualified_name_with_modules_from_root = f"{module_name_from_file_path(definition_obj.module_path, project_root_path)}.{full_name_without_module_prefix}" + + for test_func in test_functions_by_name[scope]: + if test_func.parameters is not None: + if test_framework == "pytest": + scope_test_function = f"{test_func.function_name}[{test_func.parameters}]" + else: # unittest + scope_test_function = f"{test_func.function_name}_{test_func.parameters}" + else: + scope_test_function = test_func.function_name + + function_to_test_map[qualified_name_with_modules_from_root].add( + FunctionCalledInTest( + tests_in_file=TestsInFile( + test_file=test_file, + test_class=test_func.test_class, + test_function=scope_test_function, + test_type=test_func.test_type, + ), + position=CodePosition(line_no=name.line, col_no=name.column), + ) ) - ) - num_discovered_tests += 1 + num_discovered_tests += 1 + except Exception as e: + logger.debug(str(e)) + continue progress.advance(task_id) From 97de78bc2fbf2ee086da75dbfb560aabd9e47610 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Wed, 2 Jul 2025 00:35:54 -0700 Subject: [PATCH 2/2] try except --- codeflash/discovery/discover_unit_tests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/codeflash/discovery/discover_unit_tests.py b/codeflash/discovery/discover_unit_tests.py index 3968b9b48..db78a9415 100644 --- a/codeflash/discovery/discover_unit_tests.py +++ b/codeflash/discovery/discover_unit_tests.py @@ -624,10 +624,9 @@ def process_test_files( except Exception as e: logger.debug(str(e)) continue - - if not definition or definition[0].type != "function": - continue try: + if not definition or definition[0].type != "function": + continue definition_obj = definition[0] definition_path = str(definition_obj.module_path)