Add a helper to return the path to the real pytohn executable

In case the test suite is running from within a virtualenv
This commit is contained in:
Pedro Algarvio 2019-04-16 12:19:23 +01:00
parent ea9d2460f0
commit 3d407e8a2e
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -12,6 +12,7 @@ from __future__ import absolute_import
import fnmatch
import os
import re
import sys
import fnmatch
import tempfile
@ -153,3 +154,23 @@ def fail_function(*args, **kwargs): # pylint: disable=unused-argument
Return False no matter what is passed to it
'''
return False
def get_python_executable():
'''
Return the path to the python executable.
This is particularly important when running the test suite within a virtualenv, while trying
to create virtualenvs on windows.
'''
try:
if salt.utils.is_windows():
python_binary = os.path.join(sys.real_prefix, os.path.basename(sys.executable))
else:
python_binary = os.path.join(sys.real_prefix, 'bin', os.path.basename(sys.executable))
if not os.path.exists(python_binary):
python_binary = None
except AttributeError:
# We're not running inside a virtualenv
python_binary = None
return python_binary