Skip to content

Commit 28eee4a

Browse files
committed
make ty happy
1 parent d5fa1ef commit 28eee4a

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def __init__(self) -> None:
7676
"""
7777
)
7878

79-
self._memory_cache = {}
80-
self._hash_cache = {}
79+
self.memory_cache = {}
8180

8281
def insert_test(
8382
self,
@@ -111,7 +110,7 @@ def insert_test(
111110
def get_tests_for_file(self, file_path: str, file_hash: str) -> list[FunctionCalledInTest] | None:
112111
cache_key = (file_path, file_hash)
113112
if cache_key in self._memory_cache:
114-
return self._memory_cache[cache_key]
113+
return self.memory_cache[cache_key]
115114

116115
self.cur.execute("SELECT * FROM discovered_tests WHERE file_path = ? AND file_hash = ?", (file_path, file_hash))
117116
rows = self.cur.fetchall()
@@ -127,7 +126,7 @@ def get_tests_for_file(self, file_path: str, file_hash: str) -> list[FunctionCal
127126
)
128127
for row in rows
129128
]
130-
self._memory_cache[cache_key] = result
129+
self.memory_cache[cache_key] = result
131130
return result
132131

133132
@staticmethod
@@ -384,7 +383,7 @@ def discover_tests_pytest(
384383
cfg: TestConfig,
385384
discover_only_these_tests: list[Path] | None = None,
386385
functions_to_optimize: list[FunctionToOptimize] | None = None,
387-
) -> tuple[dict[str, set[FunctionCalledInTest]], int]:
386+
) -> tuple[dict[str, set[FunctionCalledInTest]], int, int]:
388387
tests_root = cfg.tests_root
389388
project_root = cfg.project_root_path
390389

@@ -421,9 +420,11 @@ def discover_tests_pytest(
421420
f"Failed to collect tests. Pytest Exit code: {exitcode}={pytest.ExitCode(exitcode).name}\n {error_section}"
422421
)
423422
if "ModuleNotFoundError" in result.stdout:
424-
match = ImportErrorPattern.search(result.stdout).group()
425-
panel = Panel(Text.from_markup(f"⚠️ {match} ", style="bold red"), expand=False)
426-
console.print(panel)
423+
match = ImportErrorPattern.search(result.stdout)
424+
if match:
425+
error_message = match.group()
426+
panel = Panel(Text.from_markup(f"⚠️ {error_message} ", style="bold red"), expand=False)
427+
console.print(panel)
427428

428429
elif 0 <= exitcode <= 5:
429430
logger.warning(f"Failed to collect tests. Pytest Exit code: {exitcode}={pytest.ExitCode(exitcode).name}")
@@ -460,7 +461,7 @@ def discover_tests_unittest(
460461
cfg: TestConfig,
461462
discover_only_these_tests: list[str] | None = None,
462463
functions_to_optimize: list[FunctionToOptimize] | None = None,
463-
) -> tuple[dict[str, set[FunctionCalledInTest]], int]:
464+
) -> tuple[dict[str, set[FunctionCalledInTest]], int, int]:
464465
tests_root: Path = cfg.tests_root
465466
loader: unittest.TestLoader = unittest.TestLoader()
466467
tests: unittest.TestSuite = loader.discover(str(tests_root))
@@ -516,9 +517,9 @@ def get_test_details(_test: unittest.TestCase) -> TestsInFile | None:
516517

517518

518519
def discover_parameters_unittest(function_name: str) -> tuple[bool, str, str | None]:
519-
function_name = function_name.split("_")
520-
if len(function_name) > 1 and function_name[-1].isdigit():
521-
return True, "_".join(function_name[:-1]), function_name[-1]
520+
function_parts = function_name.split("_")
521+
if len(function_parts) > 1 and function_parts[-1].isdigit():
522+
return True, "_".join(function_parts[:-1]), function_parts[-1]
522523

523524
return False, function_name, None
524525

0 commit comments

Comments
 (0)