mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix ansible-test handling of import/syntax errors.
This commit is contained in:
parent
3648e6fd2b
commit
0cf1e8e061
1 changed files with 7 additions and 6 deletions
|
@ -156,11 +156,10 @@ def extract_python_module_utils_imports(path, module_utils):
|
||||||
try:
|
try:
|
||||||
tree = ast.parse(code)
|
tree = ast.parse(code)
|
||||||
except SyntaxError as ex:
|
except SyntaxError as ex:
|
||||||
# Setting the full path to the filename results in only the filename being given for str(ex).
|
# Treat this error as a warning so tests can be executed as best as possible.
|
||||||
# As a work-around, set the filename to a UUID and replace it in the final string output with the actual path.
|
# The compile test will detect and report this syntax error.
|
||||||
ex.filename = str(uuid.uuid4())
|
display.warning('%s:%s Syntax error extracting module_utils imports: %s' % (path, ex.lineno, ex.msg))
|
||||||
error = str(ex).replace(ex.filename, path)
|
return set()
|
||||||
raise ApplicationError('AST parse error: %s' % error)
|
|
||||||
|
|
||||||
finder = ModuleUtilFinder(path, module_utils)
|
finder = ModuleUtilFinder(path, module_utils)
|
||||||
finder.visit(tree)
|
finder.visit(tree)
|
||||||
|
@ -239,4 +238,6 @@ class ModuleUtilFinder(ast.NodeVisitor):
|
||||||
if self.path.startswith('test/'):
|
if self.path.startswith('test/'):
|
||||||
return # invalid imports in tests are ignored
|
return # invalid imports in tests are ignored
|
||||||
|
|
||||||
raise ApplicationError('%s:%d Invalid module_utils import: %s' % (self.path, line_number, import_name))
|
# Treat this error as a warning so tests can be executed as best as possible.
|
||||||
|
# This error should be detected by unit or integration tests.
|
||||||
|
display.warning('%s:%d Invalid module_utils import: %s' % (self.path, line_number, import_name))
|
||||||
|
|
Loading…
Reference in a new issue