Skip to content

Commit 47d6fa4

Browse files
Update codeflash/discovery/discover_unit_tests.py
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
1 parent cdaf4a8 commit 47d6fa4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,21 @@ def visit_Assign(self, node: ast.Assign) -> None:
263263
return
264264

265265
# Check if the assignment is a class instantiation
266-
if isinstance(node.value, ast.Call) and isinstance(node.value.func, ast.Name):
266+
handled_assignment = False
267+
if isinstance(node.value, ast.Call) and type(node.value.func) is ast.Name:
267268
class_name = node.value.func.id
268269
if class_name in self.imported_modules:
269270
# Track all target variables as instances of the imported class
270271
for target in node.targets:
271-
if isinstance(target, ast.Name):
272+
if type(target) is ast.Name:
272273
# Map the variable to the actual class name (handling aliases)
273274
original_class = self.alias_mapping.get(class_name, class_name)
274275
self.instance_mapping[target.id] = original_class
276+
handled_assignment = True
275277

276-
self.generic_visit(node)
278+
# Only traverse child nodes if we didn't handle a class instantiation assignment
279+
if not handled_assignment:
280+
self.generic_visit(node)
277281

278282
def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
279283
"""Handle 'from module import name' statements."""

0 commit comments

Comments
 (0)