From 1e02a201a60d196053ff52213115bf2ea8d3eb42 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Mon, 13 Jul 2020 22:34:34 -0700 Subject: [PATCH] Fix ansible-test virtualenv management. --- changelogs/fragments/ansible-test-virtualenv-fix.yml | 2 ++ test/lib/ansible_test/_internal/venv.py | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/ansible-test-virtualenv-fix.yml diff --git a/changelogs/fragments/ansible-test-virtualenv-fix.yml b/changelogs/fragments/ansible-test-virtualenv-fix.yml new file mode 100644 index 00000000000..813d9cd85fd --- /dev/null +++ b/changelogs/fragments/ansible-test-virtualenv-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test now always uses the ``--python`` option for ``virtualenv`` to select the correct interpreter when creating environments with the ``--venv`` option diff --git a/test/lib/ansible_test/_internal/venv.py b/test/lib/ansible_test/_internal/venv.py index 4bd4abddbde..37eef367b76 100644 --- a/test/lib/ansible_test/_internal/venv.py +++ b/test/lib/ansible_test/_internal/venv.py @@ -173,10 +173,9 @@ def run_virtualenv(args, # type: EnvironmentConfig path, # type: str ): # type: (...) -> bool """Create a virtual environment using the 'virtualenv' module.""" - cmd = [run_python, '-m', 'virtualenv'] - - if run_python != env_python: - cmd += ['--python', env_python] + # always specify --python to guarantee the desired interpreter is provided + # otherwise virtualenv may select a different interpreter than the one running virtualenv + cmd = [run_python, '-m', 'virtualenv', '--python', env_python] if system_site_packages: cmd.append('--system-site-packages')