@@ -146,7 +146,8 @@ class ImportAnalyzer(ast.NodeVisitor):
146146 def __init__ (self , function_names_to_find : set [str ]) -> None :
147147 self .function_names_to_find = function_names_to_find
148148 self .found_any_target_function : bool = False
149- self .imported_modules : set [str ] = set () # Track imported modules for usage analysis
149+ self .found_qualified_name = None
150+ self .imported_modules : set [str ] = set ()
150151 self .has_dynamic_imports : bool = False
151152 self .wildcard_modules : set [str ] = set ()
152153
@@ -166,11 +167,13 @@ def visit_Import(self, node: ast.Import) -> None:
166167 # Check if module itself is a target qualified name
167168 if module_name in self .function_names_to_find :
168169 self .found_any_target_function = True
170+ self .found_qualified_name = module_name
169171 return
170172 # Check if any target qualified name starts with this module
171173 for target_func in self .function_names_to_find :
172174 if target_func .startswith (f"{ module_name } ." ):
173175 self .found_any_target_function = True
176+ self .found_qualified_name = target_func
174177 return
175178
176179 def visit_ImportFrom (self , node : ast .ImportFrom ) -> None :
@@ -195,11 +198,13 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
195198 # Check if imported name is a target qualified name
196199 if alias .name in self .function_names_to_find :
197200 self .found_any_target_function = True
201+ self .found_qualified_name = alias .name
198202 return
199203 # Check if module.name forms a target qualified name
200204 qualified_name = f"{ node .module } .{ alias .name } "
201205 if qualified_name in self .function_names_to_find :
202206 self .found_any_target_function = True
207+ self .found_qualified_name = qualified_name
203208 return
204209
205210 def visit_Attribute (self , node : ast .Attribute ) -> None :
@@ -214,12 +219,14 @@ def visit_Attribute(self, node: ast.Attribute) -> None:
214219 and node .attr in self .function_names_to_find
215220 ):
216221 self .found_any_target_function = True
222+ self .found_qualified_name = node .attr
217223 return
218224
219225 # Check if this is accessing a target function through a dynamically imported module
220226 # Only if we've detected dynamic imports are being used
221227 if self .has_dynamic_imports and node .attr in self .function_names_to_find :
222228 self .found_any_target_function = True
229+ self .found_qualified_name = node .attr
223230 return
224231
225232 self .generic_visit (node )
@@ -235,6 +242,7 @@ def visit_Name(self, node: ast.Name) -> None:
235242
236243 if node .id in self .function_names_to_find :
237244 self .found_any_target_function = True
245+ self .found_qualified_name = node .id
238246 return
239247
240248 # Check if this name could come from a wildcard import
@@ -243,6 +251,7 @@ def visit_Name(self, node: ast.Name) -> None:
243251 # Check if target_func is from this wildcard module and name matches
244252 if target_func .startswith (f"{ wildcard_module } ." ) and target_func .endswith (f".{ node .id } " ):
245253 self .found_any_target_function = True
254+ self .found_qualified_name = target_func
246255 return
247256
248257 self .generic_visit (node )
@@ -266,7 +275,11 @@ def analyze_imports_in_test_file(test_file_path: Path | str, target_functions: s
266275 logger .debug (f"Failed to analyze imports in { test_file_path } : { e } " )
267276 return True
268277 else :
269- return analyzer .found_any_target_function
278+ if analyzer .found_any_target_function :
279+ logger .debug (f"Test file { test_file_path } imports target function: { analyzer .found_qualified_name } " )
280+ return True
281+ logger .debug (f"Test file { test_file_path } does not import any target functions." )
282+ return False
270283
271284
272285def filter_test_files_by_imports (
@@ -288,7 +301,6 @@ def filter_test_files_by_imports(
288301 logger .debug (f"Target functions for import filtering: { target_functions } " )
289302
290303 filtered_map = {}
291-
292304 for test_file , test_functions in file_to_test_map .items ():
293305 should_process = analyze_imports_in_test_file (test_file , target_functions )
294306 if should_process :
@@ -315,7 +327,6 @@ def discover_unit_tests(
315327 functions_to_optimize = None
316328 if file_to_funcs_to_optimize :
317329 functions_to_optimize = [func for funcs_list in file_to_funcs_to_optimize .values () for func in funcs_list ]
318-
319330 function_to_tests , num_discovered_tests = strategy (cfg , discover_only_these_tests , functions_to_optimize )
320331 return function_to_tests , num_discovered_tests
321332
0 commit comments