From 77732ed50db3b8e27d463663f347088334094bed Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 20 Mar 2020 17:49:33 -0700 Subject: Fix ansible-test import analysis warning. Fix overlooked in https://github.com/ansible/ansible/pull/68372/ --- test/lib/ansible_test/_internal/import_analysis.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/lib/ansible_test/_internal/import_analysis.py b/test/lib/ansible_test/_internal/import_analysis.py index b718e04a60..64b2e993c0 100644 --- a/test/lib/ansible_test/_internal/import_analysis.py +++ b/test/lib/ansible_test/_internal/import_analysis.py @@ -190,7 +190,7 @@ def get_import_path(name, package=False): # type: (str, bool) -> str else: filename = '%s.py' % name.replace('.', '/') - if name.startswith('ansible.module_utils.'): + if name.startswith('ansible.module_utils.') or name == 'ansible.module_utils': path = os.path.join('lib', filename) elif data_context().content.collection and name.startswith('ansible_collections.%s.plugins.module_utils.' % data_context().content.collection.full_name): path = '/'.join(filename.split('/')[3:]) @@ -274,6 +274,11 @@ class ModuleUtilFinder(ast.NodeVisitor): if is_subdir(self.path, data_context().content.test_path): return # invalid imports in tests are ignored + path = get_import_path(name, True) + + if os.path.exists(path) and os.path.getsize(path) == 0: + return # zero length __init__.py files are ignored during earlier processing, do not warn about them now + # 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)) -- cgit v1.2.1