Simplify virtualenv test in test_testing
This commit is contained in:
@@ -200,7 +200,6 @@ def build(options: BuildOptions) -> None:
|
|||||||
pip install {dependency_install_flags} virtualenv
|
pip install {dependency_install_flags} virtualenv
|
||||||
venv_dir=`mktemp -d`/venv
|
venv_dir=`mktemp -d`/venv
|
||||||
python -m virtualenv --no-download "$venv_dir"
|
python -m virtualenv --no-download "$venv_dir"
|
||||||
export __CIBW_VIRTUALENV_PATH__=$venv_dir
|
|
||||||
|
|
||||||
# run the tests in a subshell to keep that `activate`
|
# run the tests in a subshell to keep that `activate`
|
||||||
# script from polluting the env
|
# script from polluting the env
|
||||||
|
|||||||
@@ -224,7 +224,6 @@ def build(options: BuildOptions) -> None:
|
|||||||
os.path.join(venv_dir, 'bin'),
|
os.path.join(venv_dir, 'bin'),
|
||||||
virtualenv_env['PATH'],
|
virtualenv_env['PATH'],
|
||||||
])
|
])
|
||||||
virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir
|
|
||||||
|
|
||||||
# check that we are using the Python from the virtual environment
|
# check that we are using the Python from the virtual environment
|
||||||
call(['which', 'python'], env=virtualenv_env)
|
call(['which', 'python'], env=virtualenv_env)
|
||||||
|
|||||||
@@ -206,13 +206,10 @@ def build(options: BuildOptions) -> None:
|
|||||||
shell(['python', '-m', 'virtualenv', '--no-download', venv_dir], env=env)
|
shell(['python', '-m', 'virtualenv', '--no-download', venv_dir], env=env)
|
||||||
|
|
||||||
virtualenv_env = env.copy()
|
virtualenv_env = env.copy()
|
||||||
|
|
||||||
venv_script_path = os.path.join(venv_dir, 'Scripts')
|
|
||||||
virtualenv_env['PATH'] = os.pathsep.join([
|
virtualenv_env['PATH'] = os.pathsep.join([
|
||||||
venv_script_path,
|
os.path.join(venv_dir, 'Scripts'),
|
||||||
virtualenv_env['PATH'],
|
virtualenv_env['PATH'],
|
||||||
])
|
])
|
||||||
virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir
|
|
||||||
|
|
||||||
# check that we are using the Python from the virtual environment
|
# check that we are using the Python from the virtual environment
|
||||||
shell(['which', 'python'], env=virtualenv_env)
|
shell(['which', 'python'], env=virtualenv_env)
|
||||||
|
|||||||
@@ -46,12 +46,15 @@ class TestSpam(TestCase):
|
|||||||
self.assertNotEqual(0, spam.system('python -c "exit(1)"'))
|
self.assertNotEqual(0, spam.system('python -c "exit(1)"'))
|
||||||
|
|
||||||
def test_virtualenv(self):
|
def test_virtualenv(self):
|
||||||
virtualenv_path = os.environ.get("__CIBW_VIRTUALENV_PATH__")
|
# sys.prefix is different from sys.base_prefix when running a virtualenv
|
||||||
if not virtualenv_path:
|
# See https://docs.python.org/3/library/venv.html, which virtualenv seems
|
||||||
self.fail("No virtualenv path defined in environment variable __CIBW_VIRTUALENV_PATH__")
|
# to honor in recent releases
|
||||||
|
# Python 2 doesn't have sys.base_prefix by default
|
||||||
|
if not hasattr(sys, 'base_prefix') or sys.prefix == sys.base_prefix:
|
||||||
|
self.fail("Not running in a virtualenv")
|
||||||
|
|
||||||
self.assertTrue(path_contains(virtualenv_path, sys.executable))
|
self.assertTrue(path_contains(sys.prefix, sys.executable))
|
||||||
self.assertTrue(path_contains(virtualenv_path, spam.__file__))
|
self.assertTrue(path_contains(sys.prefix, spam.__file__))
|
||||||
|
|
||||||
def test_uname(self):
|
def test_uname(self):
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
|||||||
Reference in New Issue
Block a user