Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_tests(path):
"""Collect tests for the test module located at ``path``."""
tests = []
with open(path) as handler:
root = ast.parse(handler.read())
root.path = path # TODO improve how to pass the path to TestFunction
for node in ast.iter_child_nodes(root):
if isinstance(node, ast.ClassDef):
[
tests.append(TestFunction(subnode, node, root))
for subnode in ast.iter_child_nodes(node)
if isinstance(subnode, ast.FunctionDef) and
subnode.name.startswith('test_')
]
elif (isinstance(node, ast.FunctionDef) and
node.name.startswith('test_')):
tests.append(TestFunction(node, testmodule=root))
return tests
"""Collect tests for the test module located at ``path``."""
tests = []
with open(path) as handler:
root = ast.parse(handler.read())
root.path = path # TODO improve how to pass the path to TestFunction
for node in ast.iter_child_nodes(root):
if isinstance(node, ast.ClassDef):
[
tests.append(TestFunction(subnode, node, root))
for subnode in ast.iter_child_nodes(node)
if isinstance(subnode, ast.FunctionDef) and
subnode.name.startswith('test_')
]
elif (isinstance(node, ast.FunctionDef) and
node.name.startswith('test_')):
tests.append(TestFunction(node, testmodule=root))
return tests