summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2023-05-01 09:41:43 -0700
committerGitHub <noreply@github.com>2023-05-01 09:41:43 -0700
commit884215bd1c3c2cb59920db39436c081909b14f01 (patch)
tree0f5a240f5c0ca05986a24a4c15db2d22b18bfb4d
parentd37678c5ff221ada71afc0cad3ff7b70e0a0ec2f (diff)
downloadansible-884215bd1c3c2cb59920db39436c081909b14f01.tar.gz
Improve unit test code coverage (#80683)
-rw-r--r--test/units/_vendor/test_vendor.py17
1 files 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