From 33a8d063327f8e3053799c001eaa21b660cb428e Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Mon, 6 Dec 2021 11:27:27 -0800 Subject: [PATCH] ansible-test - Fix import test when vendoring. --- changelogs/fragments/ansible-test-sanity-vendoring.yml | 2 ++ lib/ansible/_vendor/__init__.py | 1 + .../lib/ansible_test/_util/target/sanity/import/importer.py | 6 ++++++ 3 files changed, 9 insertions(+) create mode 100644 changelogs/fragments/ansible-test-sanity-vendoring.yml diff --git a/changelogs/fragments/ansible-test-sanity-vendoring.yml b/changelogs/fragments/ansible-test-sanity-vendoring.yml new file mode 100644 index 00000000000..7b6803da904 --- /dev/null +++ b/changelogs/fragments/ansible-test-sanity-vendoring.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Fix the ``import`` sanity test to work properly when Ansible's built-in vendoring support is in use. diff --git a/lib/ansible/_vendor/__init__.py b/lib/ansible/_vendor/__init__.py index a31957b6724..21f3efedf97 100644 --- a/lib/ansible/_vendor/__init__.py +++ b/lib/ansible/_vendor/__init__.py @@ -39,6 +39,7 @@ def _ensure_vendored_path_entry(): already_loaded_vendored_modules = set(sys.modules.keys()).intersection(vendored_module_names) if already_loaded_vendored_modules: + # NOTE: If this message is changed, the matching warning filter in ansible-test must also be updated in `importer.py` for the import sanity test. warnings.warn('One or more Python packages bundled by this ansible-core distribution were already ' 'loaded ({0}). This may result in undefined behavior.'.format(', '.join(sorted(already_loaded_vendored_modules)))) diff --git a/test/lib/ansible_test/_util/target/sanity/import/importer.py b/test/lib/ansible_test/_util/target/sanity/import/importer.py index c506a9cefb1..4708abf1533 100644 --- a/test/lib/ansible_test/_util/target/sanity/import/importer.py +++ b/test/lib/ansible_test/_util/target/sanity/import/importer.py @@ -475,6 +475,12 @@ def main(): with warnings.catch_warnings(): warnings.simplefilter('error') + # If vendoring is in use (lib/ansible/_vendor/), then vendored modules may already be loaded after the first file is tested. + # To avoid test failures, the warning about this condition must be ignored. + warnings.filterwarnings( + "ignore", + "One or more Python packages bundled by this ansible-core distribution were already loaded ") + if sys.version_info[0] == 2: warnings.filterwarnings( "ignore",