Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove concurrency problem in no-db tests and mock by late import #43942

Closed
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
21 changes: 20 additions & 1 deletion providers/tests/standard/utils/test_python_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import pytest

from airflow.providers.standard.utils.python_virtualenv import _generate_pip_conf, _use_uv, prepare_virtualenv
from airflow.utils.decorators import remove_task_decorator

from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS
Expand All @@ -32,6 +31,8 @@
class TestPrepareVirtualenv:
@mock.patch("shutil.which")
def test_use_uv(self, mock_shutil_which):
from airflow.providers.standard.utils.python_virtualenv import _use_uv

with conf_vars({("standard", "venv_install_method"): "auto"}):
mock_shutil_which.side_effect = [True]
assert _use_uv() is True
Expand Down Expand Up @@ -69,6 +70,8 @@ def test_generate_pip_conf(
unexpected_pip_conf_content: list[str],
tmp_path: Path,
):
from airflow.providers.standard.utils.python_virtualenv import _generate_pip_conf

tmp_file = tmp_path / "pip.conf"
_generate_pip_conf(tmp_file, index_urls)
generated_conf = tmp_file.read_text()
Expand All @@ -80,6 +83,8 @@ def test_generate_pip_conf(
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "pip"})
def test_should_create_virtualenv_pip(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

python_bin = prepare_virtualenv(
venv_directory="/VENV", python_bin="pythonVER", system_site_packages=False, requirements=[]
)
Expand All @@ -89,6 +94,8 @@ def test_should_create_virtualenv_pip(self, mock_execute_in_subprocess):
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "uv"})
def test_should_create_virtualenv_uv(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

python_bin = prepare_virtualenv(
venv_directory="/VENV", python_bin="pythonVER", system_site_packages=False, requirements=[]
)
Expand All @@ -100,6 +107,8 @@ def test_should_create_virtualenv_uv(self, mock_execute_in_subprocess):
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "pip"})
def test_should_create_virtualenv_with_system_packages_pip(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

python_bin = prepare_virtualenv(
venv_directory="/VENV", python_bin="pythonVER", system_site_packages=True, requirements=[]
)
Expand All @@ -111,6 +120,8 @@ def test_should_create_virtualenv_with_system_packages_pip(self, mock_execute_in
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "uv"})
def test_should_create_virtualenv_with_system_packages_uv(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

python_bin = prepare_virtualenv(
venv_directory="/VENV", python_bin="pythonVER", system_site_packages=True, requirements=[]
)
Expand All @@ -131,6 +142,8 @@ def test_should_create_virtualenv_with_system_packages_uv(self, mock_execute_in_
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "pip"})
def test_pip_install_options_pip(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

pip_install_options = ["--no-deps"]
python_bin = prepare_virtualenv(
venv_directory="/VENV",
Expand All @@ -148,6 +161,8 @@ def test_pip_install_options_pip(self, mock_execute_in_subprocess):
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "uv"})
def test_pip_install_options_uv(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

pip_install_options = ["--no-deps"]
python_bin = prepare_virtualenv(
venv_directory="/VENV",
Expand All @@ -165,6 +180,8 @@ def test_pip_install_options_uv(self, mock_execute_in_subprocess):
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "pip"})
def test_should_create_virtualenv_with_extra_packages_pip(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

python_bin = prepare_virtualenv(
venv_directory="/VENV",
python_bin="pythonVER",
Expand All @@ -180,6 +197,8 @@ def test_should_create_virtualenv_with_extra_packages_pip(self, mock_execute_in_
@mock.patch("airflow.providers.standard.utils.python_virtualenv.execute_in_subprocess")
@conf_vars({("standard", "venv_install_method"): "uv"})
def test_should_create_virtualenv_with_extra_packages_uv(self, mock_execute_in_subprocess):
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv

python_bin = prepare_virtualenv(
venv_directory="/VENV",
python_bin="pythonVER",
Expand Down
Loading