Skip to content

Commit 27784fe

Browse files
committed
Revert "implement suggestions"
This reverts commit ad9b306.
1 parent ad9b306 commit 27784fe

File tree

1 file changed

+59
-46
lines changed

1 file changed

+59
-46
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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_by_name: dict[str, TestFunction] = {}
214+
test_functions = set()
215215

216216
all_names = script.get_names(all_scopes=True, references=True)
217217
all_defs = script.get_names(all_scopes=True, definitions=True)
@@ -238,18 +238,22 @@ def process_test_files(
238238
function.test_function
239239
)[1]
240240
if function_name in top_level_functions:
241-
test_functions_by_name[function_name] = TestFunction(
242-
function_name,
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,
243253
function.test_class,
244-
parameters,
254+
None,
245255
function.test_type,
246256
)
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,
253257
)
254258
elif UNITTEST_PARAMETERIZED_TEST_NAME_REGEX.match(
255259
function.test_function
@@ -258,11 +262,13 @@ def process_test_files(
258262
"", function.test_function
259263
)
260264
if base_name in top_level_functions:
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,
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+
)
266272
)
267273

268274
elif test_framework == "unittest":
@@ -283,7 +289,7 @@ def process_test_files(
283289
)
284290

285291
if is_parameterized and new_function == def_name.name:
286-
test_functions_by_name[def_name.name] = (
292+
test_functions.add(
287293
TestFunction(
288294
function_name=def_name.name,
289295
test_class=matched_name,
@@ -292,7 +298,7 @@ def process_test_files(
292298
)
293299
)
294300
elif function == def_name.name:
295-
test_functions_by_name[def_name.name] = (
301+
test_functions.add(
296302
TestFunction(
297303
function_name=def_name.name,
298304
test_class=matched_name,
@@ -301,6 +307,13 @@ def process_test_files(
301307
)
302308
)
303309

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+
304317
for name in all_names:
305318
if name.full_name is None:
306319
continue
@@ -334,36 +347,36 @@ def process_test_files(
334347
and definition[0].module_name != name.module_name
335348
and definition[0].full_name is not None
336349
):
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-
),
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+
)
365379
)
366-
)
367380

368381
progress.advance(task_id)
369382

0 commit comments

Comments
 (0)