Skip to content

Commit 86a8d20

Browse files
author
Codeflash Bot
committed
possible fix
1 parent 105735f commit 86a8d20

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,58 @@ def process_test_files(
868868
continue
869869
try:
870870
if not definition or definition[0].type != "function":
871+
# Fallback: Try to match against functions_to_optimize when Jedi can't resolve
872+
# This handles cases where Jedi fails with pytest fixtures
873+
if functions_to_optimize and name.name:
874+
for func_to_opt in functions_to_optimize:
875+
# Check if this unresolved name matches a function we're looking for
876+
if func_to_opt.function_name == name.name:
877+
# Check if the test file imports the class/module containing this function
878+
qualified_name_with_modules = func_to_opt.qualified_name_with_modules_from_root(
879+
project_root_path
880+
)
881+
882+
# Only add if this test actually tests the function we're optimizing
883+
for test_func in test_functions_by_name[scope]:
884+
if test_func.parameters is not None:
885+
if test_framework == "pytest":
886+
scope_test_function = (
887+
f"{test_func.function_name}[{test_func.parameters}]"
888+
)
889+
else: # unittest
890+
scope_test_function = (
891+
f"{test_func.function_name}_{test_func.parameters}"
892+
)
893+
else:
894+
scope_test_function = test_func.function_name
895+
896+
function_to_test_map[qualified_name_with_modules].add(
897+
FunctionCalledInTest(
898+
tests_in_file=TestsInFile(
899+
test_file=test_file,
900+
test_class=test_func.test_class,
901+
test_function=scope_test_function,
902+
test_type=test_func.test_type,
903+
),
904+
position=CodePosition(line_no=name.line, col_no=name.column),
905+
)
906+
)
907+
tests_cache.insert_test(
908+
file_path=str(test_file),
909+
file_hash=file_hash,
910+
qualified_name_with_modules_from_root=qualified_name_with_modules,
911+
function_name=scope,
912+
test_class=test_func.test_class or "",
913+
test_function=scope_test_function,
914+
test_type=test_func.test_type,
915+
line_number=name.line,
916+
col_number=name.column,
917+
)
918+
919+
if test_func.test_type == TestType.REPLAY_TEST:
920+
num_discovered_replay_tests += 1
921+
922+
num_discovered_tests += 1
871923
continue
872924
definition_obj = definition[0]
873925
definition_path = str(definition_obj.module_path)

0 commit comments

Comments
 (0)