Files
crewAI/tests/test_optional_dependencies.py
Vini Brasil 257f4bf385 Test optional dependencies are not required in runtime (#260)
* Test optional dependencies are not required in runtime

* Add dynamic imports to S3 tools

* Setup CI
2025-04-08 13:20:11 -04:00

41 lines
1.2 KiB
Python

import subprocess
import tempfile
from pathlib import Path
import pytest
@pytest.fixture
def temp_project():
temp_dir = tempfile.TemporaryDirectory()
project_dir = Path(temp_dir.name) / "test_project"
project_dir.mkdir()
pyproject_content = f"""
[project]
name = "test-project"
version = "0.1.0"
description = "Test project"
requires-python = ">=3.10"
"""
(project_dir / "pyproject.toml").write_text(pyproject_content)
run_command(["uv", "add", "--editable", f"file://{Path.cwd().absolute()}"], project_dir)
run_command(["uv", "sync"], project_dir)
yield project_dir
def run_command(cmd, cwd):
return subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
def test_no_optional_dependencies_in_init(temp_project):
"""
Test that crewai-tools can be imported without optional dependencies.
The package defines optional dependencies in pyproject.toml, but the base
package should be importable without any of these optional dependencies
being installed.
"""
result = run_command(["uv", "run", "python", "-c", "import crewai_tools"], temp_project)
assert result.returncode == 0, f"Import failed with error: {result.stderr}"