From cd4736d893a47c9ebd7796d8c9fec5180ca22488 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 20 Aug 2019 11:44:39 +0200 Subject: [PATCH] missing_required_lib: add information how to change Python interpreter (#60736) * Add information how to change Python interpreter used by Ansible. * Update lib/ansible/module_utils/basic.py Co-Authored-By: Abhijeet Kasurde * Make test less dependent on exact message. --- lib/ansible/module_utils/basic.py | 5 ++++- test/units/plugins/lookup/test_laps_password.py | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index d25915c8247..1e11bea4e58 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -567,7 +567,10 @@ def missing_required_lib(library, reason=None, url=None): if url: msg += " See %s for more info." % url - return msg + " Please read module documentation and install in the appropriate location" + msg += (" Please read module documentation and install in the appropriate location." + " If the required library is installed, but Ansible is using the wrong Python interpreter," + " please consult the documentation on ansible_python_interpreter") + return msg class AnsibleFallbackNotFound(Exception): diff --git a/test/units/plugins/lookup/test_laps_password.py b/test/units/plugins/lookup/test_laps_password.py index a778e8b465e..af0664e6a68 100644 --- a/test/units/plugins/lookup/test_laps_password.py +++ b/test/units/plugins/lookup/test_laps_password.py @@ -108,10 +108,12 @@ def test_missing_ldap(laps_password): with pytest.raises(AnsibleLookupError) as err: lookup_loader.get('laps_password').run(["host"], domain="test") - assert str(err.value) == "Failed to import the required Python library (python-ldap) on %s's Python %s. See " \ - "https://pypi.org/project/python-ldap/ for more info. Please read module documentation " \ - "and install in the appropriate location. " \ - "Import Error: no import for you!" % (platform.node(), sys.executable) + assert str(err.value).startswith( + "Failed to import the required Python library (python-ldap) on %s's Python %s. See " + "https://pypi.org/project/python-ldap/ for more info. Please " + % (platform.node(), sys.executable) + ) + assert str(err.value).endswith(". Import Error: no import for you!") def test_invalid_cert_mapping():