diff --git a/pyproject.toml b/pyproject.toml index 4a924eb1f..e6841571b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "auth0-python>=4.7.1", "python-dotenv>=1.0.0", # Configuration and Utils - "click>=8.0.1", + "click>=8.0.1,<8.2.0", "appdirs>=1.4.4", "jsonref>=1.1.0", "json-repair>=0.25.2", diff --git a/tests/cli/test_click_compatibility.py b/tests/cli/test_click_compatibility.py index fbdfe8b04..43f3a6c93 100644 --- a/tests/cli/test_click_compatibility.py +++ b/tests/cli/test_click_compatibility.py @@ -4,45 +4,72 @@ import tempfile import pytest +# Constants for test configuration +VENV_PATH = "venv" +TEST_COMMAND = "version" +EXPECTED_OUTPUT = "crewai version" +IMPORT_SUCCESS_MESSAGE = "CLI import successful" -def test_crewai_cli_works_with_compatible_click_version(): - """Test that crewAI CLI works with Click version compatible with zenml.""" + +def run_subprocess(*args, **kwargs): + """Helper function to run subprocess with error handling.""" + try: + result = subprocess.run(*args, **kwargs) + result.check_returncode() + return result + except subprocess.CalledProcessError as e: + pytest.fail(f"Subprocess failed with exit code {e.returncode}: {e.stderr if hasattr(e, 'stderr') else ''}") + + +@pytest.mark.parametrize("click_version", ["8.0.1", "8.1.3", "8.1.4"]) +def test_crewai_cli_works_with_compatible_click_version(click_version): + """ + Verifies crewAI CLI works with multiple Click versions. + + Dependencies: + - Click versions compatible with zenml constraints + + Parameters: + click_version: The version of Click to test with + """ # Create a temporary virtual environment with tempfile.TemporaryDirectory() as temp_dir: + venv_path = f"{temp_dir}/{VENV_PATH}" + # Create a new virtual environment - subprocess.run( - [sys.executable, "-m", "venv", f"{temp_dir}/venv"], + run_subprocess( + [sys.executable, "-m", "venv", venv_path], check=True, ) - # Install Click 8.1.3 (compatible with zenml's constraints) - subprocess.run( - [f"{temp_dir}/venv/bin/pip", "install", "click==8.1.3"], + # Install specific Click version (compatible with zenml's constraints) + run_subprocess( + [f"{venv_path}/bin/pip", "install", f"click=={click_version}"], check=True, ) # Install crewai in development mode - subprocess.run( - [f"{temp_dir}/venv/bin/pip", "install", "-e", "."], + run_subprocess( + [f"{venv_path}/bin/pip", "install", "-e", "."], check=True, ) # Verify that the crewai CLI can be imported and run - result = subprocess.run( - [f"{temp_dir}/venv/bin/python", "-c", "from crewai.cli.cli import crewai; print('CLI import successful')"], + result = run_subprocess( + [f"{venv_path}/bin/python", "-c", "from crewai.cli.cli import crewai; print('CLI import successful')"], capture_output=True, text=True, ) - assert result.returncode == 0 - assert "CLI import successful" in result.stdout + assert result.returncode == 0, f"CLI import failed with output: {result.stderr}" + assert IMPORT_SUCCESS_MESSAGE in result.stdout, "Failed to import CLI module" # Test running a basic CLI command - result = subprocess.run( - [f"{temp_dir}/venv/bin/python", "-m", "crewai.cli.cli", "version"], + result = run_subprocess( + [f"{venv_path}/bin/python", "-m", "crewai.cli.cli", TEST_COMMAND], capture_output=True, text=True, ) - assert result.returncode == 0 - assert "crewai version" in result.stdout + assert result.returncode == 0, f"CLI command failed with output: {result.stderr}" + assert EXPECTED_OUTPUT in result.stdout, f"Expected output '{EXPECTED_OUTPUT}' not found in command result"