From 884215bd1c3c2cb59920db39436c081909b14f01 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Mon, 1 May 2023 09:41:43 -0700 Subject: Improve unit test code coverage (#80683) --- test/units/_vendor/test_vendor.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/test/units/_vendor/test_vendor.py b/test/units/_vendor/test_vendor.py index 0d21ef0431..265f5b27b9 100644 --- a/test/units/_vendor/test_vendor.py +++ b/test/units/_vendor/test_vendor.py @@ -1,9 +1,6 @@ # (c) 2020 Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - import os import pkgutil import pytest @@ -16,12 +13,10 @@ def reset_internal_vendor_package(): import ansible ansible_vendor_path = os.path.join(os.path.dirname(ansible.__file__), '_vendor') - if ansible_vendor_path in sys.path: - sys.path.remove(ansible_vendor_path) + list(map(sys.path.remove, [path for path in sys.path if path == ansible_vendor_path])) for pkg in ['ansible._vendor', 'ansible']: - if pkg in sys.modules: - del sys.modules[pkg] + sys.modules.pop(pkg, None) def test_package_path_masking(): @@ -50,16 +45,10 @@ def test_vendored(vendored_pkg_names=None): import ansible ansible_vendor_path = os.path.join(os.path.dirname(ansible.__file__), '_vendor') assert sys.path[0] == ansible_vendor_path - - if ansible_vendor_path in previous_path: - previous_path.remove(ansible_vendor_path) - assert sys.path[1:] == previous_path def test_vendored_conflict(): with pytest.warns(UserWarning) as w: - import pkgutil - import sys test_vendored(vendored_pkg_names=['sys', 'pkgutil']) # pass a real package we know is already loaded - assert any('pkgutil, sys' in str(msg.message) for msg in w) # ensure both conflicting modules are listed and sorted + assert any(list('pkgutil, sys' in str(msg.message) for msg in w)) # ensure both conflicting modules are listed and sorted -- cgit v1.2.1