Skip to content

Commit ca8a77d

Browse files
committed
fix tests & remove goto cache
1 parent a936077 commit ca8a77d

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,8 @@ def discover_unit_tests(
315315
# Extract all functions to optimize for import filtering
316316
functions_to_optimize = None
317317
if file_to_funcs_to_optimize:
318-
functions_to_optimize = [
319-
func for funcs_list in file_to_funcs_to_optimize.values() for func in funcs_list
320-
]
321-
318+
functions_to_optimize = [func for funcs_list in file_to_funcs_to_optimize.values() for func in funcs_list]
319+
322320
return strategy(cfg, discover_only_these_tests, functions_to_optimize)
323321

324322

@@ -493,7 +491,6 @@ def process_test_files(
493491

494492
function_to_test_map = defaultdict(set)
495493
jedi_project = jedi.Project(path=project_root_path)
496-
goto_cache = {}
497494
tests_cache = TestsCache()
498495

499496
with test_files_progress_bar(total=len(file_to_test_map), description="Processing test files") as (
@@ -607,13 +604,8 @@ def process_test_files(
607604
if scope not in test_functions_by_name:
608605
continue
609606

610-
cache_key = (name.full_name, name.module_name)
611607
try:
612-
if cache_key in goto_cache:
613-
definition = goto_cache[cache_key]
614-
else:
615-
definition = name.goto(follow_imports=True, follow_builtin_imports=False)
616-
goto_cache[cache_key] = definition
608+
definition = name.goto(follow_imports=True, follow_builtin_imports=False)
617609
except Exception as e:
618610
logger.debug(str(e))
619611
continue

tests/test_unit_test_discovery.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,13 +1079,9 @@ def test_other():
10791079
mock_function.function_name = "target_function"
10801080
mock_function.parents = [] # No parent classes
10811081

1082-
filtered_tests = discover_unit_tests(test_config, functions_to_optimize=[mock_function])
1083-
# The import filter is designed for high recall, so it may include both functions
1084-
# because both test files import from the same module (mycode) that contains target_function
1085-
assert len(filtered_tests) >= 1 # Should find at least target_function
1082+
filtered_tests = discover_unit_tests(test_config, file_to_funcs_to_optimize={code_file: [mock_function]})
1083+
assert len(filtered_tests) >= 1
10861084
assert "mycode.target_function" in filtered_tests
1087-
# In a perfect world we'd filter out other_function, but conservative filtering
1088-
# is acceptable for performance optimization purposes
10891085

10901086

10911087
def test_analyze_imports_conditional_import():
@@ -1225,8 +1221,8 @@ def test_unrelated():
12251221
mock_function.qualified_name_with_modules_from_root.return_value = "target_module.target_function"
12261222
mock_function.function_name = "target_function"
12271223
mock_function.parents = [] # No parent classes
1228-
1229-
filtered_tests = discover_unit_tests(test_config, functions_to_optimize=[mock_function])
1224+
1225+
filtered_tests = discover_unit_tests(test_config, file_to_funcs_to_optimize={target_file: [mock_function]})
12301226
# Should filter out the unrelated test since it imports from a different module
12311227
assert len(filtered_tests) == 1
12321228
assert "target_module.target_function" in filtered_tests

0 commit comments

Comments
 (0)