You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cached tests are added as raw TestsInFile instances, but new tests are wrapped as FunctionCalledInTest, causing type mismatches in function_to_test_map.
cached_tests=tests_cache.get_tests_for_file(str(test_file), file_hash)
ifcached_tests:
self_cur=tests_cache.curself_cur.execute(
"SELECT qualified_name_with_modules_from_root FROM discovered_tests WHERE file_path = ? AND file_hash = ?",
(str(test_file), file_hash),
)
qualified_names= [row[0] forrowinself_cur.fetchall()]
forcached, qualified_nameinzip(cached_tests, qualified_names):
function_to_test_map[qualified_name].add(cached)
return
The progress.advance(task_id) call appears misaligned after invoking _process_single_test_file, which may lead to a syntax or runtime indentation issue in process_test_files.
Some test_functions.add calls in the unittest branch lack the '+' marker in the diff and may not be executed, indicating copy-paste or indentation errors that break test discovery.
Latest suggestions up to a81bb64
Explore these optional code suggestions:
Category
Suggestion
Impact
General
Preserve correct test_type
Always using functions[0].test_type ignores the actual test type of each matching function. Build a map from function.test_function to its TestsInFile object and use that to retrieve the correct test_type.
+function_map = {elem.test_function: elem for elem in functions}+...
TestFunction(
function_name=def_name.name,
test_class=matched_name,
parameters=parameters,
- test_type=functions[0].test_type,+ test_type=function_map[function].test_type,
)
Suggestion importance[1-10]: 8
__
Why: Always using functions[0].test_type ignores the actual test type for each matching function, which can lead to misclassification; building a map to retrieve the correct test_type per function fixes this.
Medium
Reduce redundant regex calls
You’re calling the same regex split twice, which is inefficient and error-prone. Perform the split once into a tuple or list, then unpack the function_name and parameters.
if "[" in function.test_function:
- function_name = PYTEST_PARAMETERIZED_TEST_NAME_REGEX.split(function.test_function)[0]- parameters = PYTEST_PARAMETERIZED_TEST_NAME_REGEX.split(function.test_function)[1]+ parts = PYTEST_PARAMETERIZED_TEST_NAME_REGEX.split(function.test_function)+ function_name, parameters = parts[0], parts[1]
Suggestion importance[1-10]: 4
__
Why: Calling split twice with the same regex is redundant; unpacking the result once improves readability and offers a small performance benefit.
Low
Previous suggestions
Suggestions up to commit 26b738f
Category
Suggestion
Impact
General
Handle worker exceptions gracefully
Wrap the call to future.result() in a try/except block so that one worker failure doesn’t crash the entire discovery loop. Log the exception and continue to the next future.
for future in as_completed(future_to_file):
- _, local_results = future.result()+ try:+ _, local_results = future.result()+ except Exception as e:+ logger.error(f"Error processing {future_to_file[future]}: {e}")+ continue+ for qualified_name, function_called_in_test in local_results:+ function_to_test_map[qualified_name].add(function_called_in_test)
Suggestion importance[1-10]: 8
__
Why: Wrapping future.result() in a try/except prevents a single worker failure from aborting the entire discovery process, improving robustness without altering functionality.
Medium
Consolidate module import placement
Move the import of module_name_from_file_path to the top of the module alongside other imports to avoid repeated local imports inside loops and improve readability.
-from codeflash.code_utils.code_utils import module_name_from_file_path+# at top of file among other code_utils imports+from codeflash.code_utils.code_utils import ImportErrorPattern, custom_addopts, get_run_tmp_file, module_name_from_file_path
Suggestion importance[1-10]: 5
__
Why: Moving the module_name_from_file_path import to the top reduces repeated local imports and enhances readability, but has minimal impact on core functionality.
Low
Possible issue
Use correct test_type per function
Do not always use functions[0].test_type for every match, as this can assign the wrong test type. Instead, lookup the TestsInFile instance matching the current function to get its actual test_type.
TestFunction(
function_name=def_name.name,
test_class=matched_name,
parameters=parameters,
- test_type=functions[0].test_type,+ test_type=next(elem.test_type for elem in functions if elem.test_function == function),
)
Suggestion importance[1-10]: 8
__
Why: Always using functions[0].test_type can misassign test_type for non-first matches; looking up the matching TestsInFile ensures each TestFunction gets the correct test_type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement, Tests
Description
Add caching to skip unchanged tests
Extract single-file test processing helper
Improve pytest and unittest parameter parsing
Refactor process_test_files implementation
Changes walkthrough 📝
discover_unit_tests.py
Refactor test file processing with cachingcodeflash/discovery/discover_unit_tests.py
_process_single_test_filehelper functionprocess_test_filesto invoke helper