summaryrefslogtreecommitdiff
path: root/test/units/utils
diff options
context:
space:
mode:
authorMatt Davis <nitzmahone@users.noreply.github.com>2020-05-26 15:55:17 -0700
committerGitHub <noreply@github.com>2020-05-26 15:55:17 -0700
commitfa81cc6a0c44640b54e5513720d7413a762618e1 (patch)
treef304df05aaaf2c2e58b41ec8fec25103ac6e1ac3 /test/units/utils
parent5fc01c0a1d330fe0dc6cae378361093230445ef4 (diff)
downloadansible-fa81cc6a0c44640b54e5513720d7413a762618e1.tar.gz
fix delegated loading when path is not a directory (#69713)
* find_module can't pop ImportError- we need to just translate to `None` since this is a normal condition with files on sys.path (eg `/usr/lib/python36.zip`) * added test
Diffstat (limited to 'test/units/utils')
-rw-r--r--test/units/utils/collection_loader/test_collection_loader.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/units/utils/collection_loader/test_collection_loader.py b/test/units/utils/collection_loader/test_collection_loader.py
index fccc3a7798..e415b9e3d0 100644
--- a/test/units/utils/collection_loader/test_collection_loader.py
+++ b/test/units/utils/collection_loader/test_collection_loader.py
@@ -273,6 +273,15 @@ def test_path_hook_setup():
assert repr(_AnsiblePathHookFinder(object(), '/bogus/path')) == "_AnsiblePathHookFinder(path='/bogus/path')"
+def test_path_hook_importerror():
+ # ensure that AnsiblePathHookFinder.find_module swallows ImportError from path hook delegation on Py3, eg if the delegated
+ # path hook gets passed a file on sys.path (python36.zip)
+ reset_collections_loader_state()
+ path_to_a_file = os.path.join(default_test_collection_paths[0], 'ansible_collections/testns/testcoll/plugins/action/my_action.py')
+ # it's a bug if the following pops an ImportError...
+ assert _AnsiblePathHookFinder(_AnsibleCollectionFinder(), path_to_a_file).find_module('foo.bar.my_action') is None
+
+
def test_new_or_existing_module():
module_name = 'blar.test.module'
pkg_name = module_name.rpartition('.')[0]