mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
No module unloading. Maintain the Zen of Python.
This commit is contained in:
parent
4a7e529ab5
commit
026d1d77d5
1 changed files with 8 additions and 16 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue