We need to make sure the virtualenv path entry is removed when searching

This commit is contained in:
Pedro Algarvio 2019-04-16 16:11:08 +01:00
parent ff6d3c6dae
commit 7e79b182b6
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -764,11 +764,27 @@ class TestDaemon(object):
# virtualenv, we can on linux but we will still point to the virtualenv binary
# outside the virtualenv running the test suite, if that's the case.
try:
real_prefix = sys.real_prefix
# The above attribute exists, this is a virtualenv
if salt.utils.is_windows():
virtualenv_binary = os.path.join(sys.real_prefix, 'Scripts', 'virtualenv.exe')
virtualenv_binary = os.path.join(real_prefix, 'Scripts', 'virtualenv.exe')
else:
virtualenv_binary = os.path.join(sys.real_prefix, 'bin', 'virtualenv')
if not os.path.exists(virtualenv_binary):
# We need to remove the virtualenv from PATH or we'll get the virtualenv binary
# from within the virtualenv, we don't want that
path = os.environ.get('PATH')
if path is not None:
path_items = path.split(os.pathsep)
for item in path_items[:]:
if item.startswith(sys.base_prefix):
path_items.remove(item)
os.environ['PATH'] = os.pathsep.join(path_items)
virtualenv_binary = salt.utils.which('virtualenv')
if path is not None:
# Restore previous environ PATH
os.environ['PATH'] = path
if not virtualenv_binary.startswith(real_prefix):
virtualenv_binary = None
if virtualenv_binary and not os.path.exists(virtualenv_binary):
# It doesn't exist?!
virtualenv_binary = None
except AttributeError: