Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion airflow/utils/python_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#
"""Utilities for creating a virtual environment"""
import os
import sys
from collections import deque
from typing import List, Optional

Expand All @@ -27,7 +28,7 @@


def _generate_virtualenv_cmd(tmp_dir: str, python_bin: str, system_site_packages: bool) -> List[str]:
cmd = ['virtualenv', tmp_dir]
cmd = [sys.executable, '-m', 'virtualenv', tmp_dir]
if system_site_packages:
cmd.append('--system-site-packages')
if python_bin is not None:
Expand Down
11 changes: 8 additions & 3 deletions tests/utils/test_python_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# specific language governing permissions and limitations
# under the License.
#
import sys
import unittest
from unittest import mock

Expand All @@ -29,7 +30,9 @@ def test_should_create_virtualenv(self, mock_execute_in_subprocess):
venv_directory="/VENV", python_bin="pythonVER", system_site_packages=False, requirements=[]
)
assert "/VENV/bin/python" == python_bin
mock_execute_in_subprocess.assert_called_once_with(['virtualenv', '/VENV', '--python=pythonVER'])
mock_execute_in_subprocess.assert_called_once_with(
[sys.executable, '-m', 'virtualenv', '/VENV', '--python=pythonVER']
)

@mock.patch('airflow.utils.python_virtualenv.execute_in_subprocess')
def test_should_create_virtualenv_with_system_packages(self, mock_execute_in_subprocess):
Expand All @@ -38,7 +41,7 @@ def test_should_create_virtualenv_with_system_packages(self, mock_execute_in_sub
)
assert "/VENV/bin/python" == python_bin
mock_execute_in_subprocess.assert_called_once_with(
['virtualenv', '/VENV', '--system-site-packages', '--python=pythonVER']
[sys.executable, '-m', 'virtualenv', '/VENV', '--system-site-packages', '--python=pythonVER']
)

@mock.patch('airflow.utils.python_virtualenv.execute_in_subprocess')
Expand All @@ -51,7 +54,9 @@ def test_should_create_virtualenv_with_extra_packages(self, mock_execute_in_subp
)
assert "/VENV/bin/python" == python_bin

mock_execute_in_subprocess.assert_any_call(['virtualenv', '/VENV', '--python=pythonVER'])
mock_execute_in_subprocess.assert_any_call(
[sys.executable, '-m', 'virtualenv', '/VENV', '--python=pythonVER']
)

mock_execute_in_subprocess.assert_called_with(['/VENV/bin/pip', 'install', 'apache-beam[gcp]'])

Expand Down