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')