No module unloading. Maintain the Zen of Python.

This commit is contained in:
Pedro Algarvio 2019-10-11 10:41:27 +01:00
parent 4a7e529ab5
commit 026d1d77d5
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -17,24 +17,16 @@ import socket
import logging
from collections import namedtuple
TESTS_DIR = os.path.dirname(
os.path.normpath(os.path.abspath(__file__))
)
TESTS_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
CODE_DIR = os.path.dirname(TESTS_DIR)
# Change to code checkout directory
os.chdir(CODE_DIR)
try:
# If we have a system-wide salt module imported, unload it
import salt
for module in list(sys.modules):
if module.startswith(('salt',)):
try:
if not sys.modules[module].__file__.startswith(CODE_DIR):
sys.modules.pop(module)
except AttributeError:
continue
sys.path.insert(0, CODE_DIR)
except ImportError:
sys.path.insert(0, CODE_DIR)
# Make sure the current directory is the first item in sys.path
if CODE_DIR in sys.path:
sys.path.remove(CODE_DIR)
sys.path.insert(0, CODE_DIR)
# Import test libs
import tests.support.paths # pylint: disable=unused-import