@@ -211,7 +211,7 @@ def process_test_files(
211211 for test_file , functions in file_to_test_map .items ():
212212 try :
213213 script = jedi .Script (path = test_file , project = jedi_project )
214- test_functions = set ()
214+ test_functions_by_name : dict [ str , TestFunction ] = {}
215215
216216 all_names = script .get_names (all_scopes = True , references = True )
217217 all_defs = script .get_names (all_scopes = True , definitions = True )
@@ -238,22 +238,18 @@ def process_test_files(
238238 function .test_function
239239 )[1 ]
240240 if function_name in top_level_functions :
241- test_functions .add (
242- TestFunction (
243- function_name ,
244- function .test_class ,
245- parameters ,
246- function .test_type ,
247- )
248- )
249- elif function .test_function in top_level_functions :
250- test_functions .add (
251- TestFunction (
252- function .test_function ,
241+ test_functions_by_name [function_name ] = TestFunction (
242+ function_name ,
253243 function .test_class ,
254- None ,
244+ parameters ,
255245 function .test_type ,
256246 )
247+ elif function .test_function in top_level_functions :
248+ test_functions_by_name [function .test_function ] = TestFunction (
249+ function .test_function ,
250+ function .test_class ,
251+ None ,
252+ function .test_type ,
257253 )
258254 elif UNITTEST_PARAMETERIZED_TEST_NAME_REGEX .match (
259255 function .test_function
@@ -262,13 +258,11 @@ def process_test_files(
262258 "" , function .test_function
263259 )
264260 if base_name in top_level_functions :
265- test_functions .add (
266- TestFunction (
267- function_name = base_name ,
268- test_class = function .test_class ,
269- parameters = function .test_function ,
270- test_type = function .test_type ,
271- )
261+ test_functions_by_name [base_name ] = TestFunction (
262+ function_name = base_name ,
263+ test_class = function .test_class ,
264+ parameters = function .test_function ,
265+ test_type = function .test_type ,
272266 )
273267
274268 elif test_framework == "unittest" :
@@ -289,7 +283,7 @@ def process_test_files(
289283 )
290284
291285 if is_parameterized and new_function == def_name .name :
292- test_functions . add (
286+ test_functions_by_name [ def_name . name ] = (
293287 TestFunction (
294288 function_name = def_name .name ,
295289 test_class = matched_name ,
@@ -298,7 +292,7 @@ def process_test_files(
298292 )
299293 )
300294 elif function == def_name .name :
301- test_functions . add (
295+ test_functions_by_name [ def_name . name ] = (
302296 TestFunction (
303297 function_name = def_name .name ,
304298 test_class = matched_name ,
@@ -307,13 +301,6 @@ def process_test_files(
307301 )
308302 )
309303
310- test_functions_list = list (test_functions )
311- test_functions_raw = [elem .function_name for elem in test_functions_list ]
312-
313- test_functions_by_name = defaultdict (list )
314- for i , func_name in enumerate (test_functions_raw ):
315- test_functions_by_name [func_name ].append (i )
316-
317304 for name in all_names :
318305 if name .full_name is None :
319306 continue
@@ -347,36 +334,36 @@ def process_test_files(
347334 and definition [0 ].module_name != name .module_name
348335 and definition [0 ].full_name is not None
349336 ):
350- for index in test_functions_by_name [scope ]:
351- scope_test_function = test_functions_list [index ].function_name
352- scope_test_class = test_functions_list [index ].test_class
353- scope_parameters = test_functions_list [index ].parameters
354- test_type = test_functions_list [index ].test_type
355-
356- if scope_parameters is not None :
357- if test_framework == "pytest" :
358- scope_test_function += "[" + scope_parameters + "]"
359- if test_framework == "unittest" :
360- scope_test_function += "_" + scope_parameters
361-
362- full_name_without_module_prefix = definition [
363- 0
364- ].full_name .replace (definition [0 ].module_name + "." , "" , 1 )
365- qualified_name_with_modules_from_root = f"{ module_name_from_file_path (definition [0 ].module_path , project_root_path )} .{ full_name_without_module_prefix } "
366-
367- function_to_test_map [qualified_name_with_modules_from_root ].add (
368- FunctionCalledInTest (
369- tests_in_file = TestsInFile (
370- test_file = test_file ,
371- test_class = scope_test_class ,
372- test_function = scope_test_function ,
373- test_type = test_type ,
374- ),
375- position = CodePosition (
376- line_no = name .line , col_no = name .column
377- ),
378- )
337+ test_function = test_functions_by_name [scope ]
338+ scope_test_function = test_function .function_name
339+ scope_test_class = test_function .test_class
340+ scope_parameters = test_function .parameters
341+ test_type = test_function .test_type
342+
343+ if scope_parameters is not None :
344+ if test_framework == "pytest" :
345+ scope_test_function += "[" + scope_parameters + "]"
346+ if test_framework == "unittest" :
347+ scope_test_function += "_" + scope_parameters
348+
349+ full_name_without_module_prefix = definition [0 ].full_name .replace (
350+ definition [0 ].module_name + "." , "" , 1
351+ )
352+ qualified_name_with_modules_from_root = f"{ module_name_from_file_path (definition [0 ].module_path , project_root_path )} .{ full_name_without_module_prefix } "
353+
354+ function_to_test_map [qualified_name_with_modules_from_root ].add (
355+ FunctionCalledInTest (
356+ tests_in_file = TestsInFile (
357+ test_file = test_file ,
358+ test_class = scope_test_class ,
359+ test_function = scope_test_function ,
360+ test_type = test_type ,
361+ ),
362+ position = CodePosition (
363+ line_no = name .line , col_no = name .column
364+ ),
379365 )
366+ )
380367
381368 progress .advance (task_id )
382369
0 commit comments