Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Run tests with extra dependencies separately (#8246)

TomuHirataa15c42cc6393
diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml
index 7f077966a..35ce016d9 100644
--- a/.github/workflows/run_tests.yml
+++ b/.github/workflows/run_tests.yml
@@ -83,6 +83,10 @@ jobs:
args: check --fix-only
- name: Run tests with pytest
run: uv run -p .venv pytest tests/
+ - name: Install optional dependencies
+ run: uv sync -p .venv --extra dev --extra test_extras
+ - name: Run extra tests
+ run: uv run -p .venv pytest tests/ -m extra --extra
build_package:
name: Build Package
diff --git a/pyproject.toml b/pyproject.toml
index d7c60269c..ad22c6f43 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -51,6 +51,7 @@ dependencies = [
anthropic = ["anthropic>=0.18.0,<1.0.0"]
weaviate = ["weaviate-client~=4.5.4"]
aws = ["boto3~=1.34.78"]
+mcp = ["mcp; python_version >= '3.10'"]
dev = [
"pytest>=6.2.5",
"pytest-mock>=3.12.0",
@@ -62,9 +63,10 @@ dev = [
"build>=1.0.3",
"litellm>=1.60.3; sys_platform == 'win32'",
"litellm[proxy]>=1.60.3; sys_platform != 'win32'",
- "mcp>=1.5.0; python_version >= '3.10'",
]
-mcp = ["mcp; python_version >= '3.10'"]
+test_extras = [
+ "mcp; python_version >= '3.10'",
+]
[tool.setuptools.packages.find]
where = ["."]
diff --git a/tests/conftest.py b/tests/conftest.py
index 937dcb32e..dd57d03f1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -4,7 +4,7 @@ import pytest
from tests.test_utils.server import litellm_test_server, read_litellm_test_server_request_logs # noqa: F401
-SKIP_DEFAULT_FLAGS = ["reliability"]
+SKIP_DEFAULT_FLAGS = ["reliability", "extra"]
@pytest.fixture(autouse=True)
diff --git a/tests/utils/test_mcp.py b/tests/utils/test_mcp.py
index ab11682f1..296db0e2c 100644
--- a/tests/utils/test_mcp.py
+++ b/tests/utils/test_mcp.py
@@ -1,14 +1,19 @@
import asyncio
+import importlib
import pytest
-from mcp import ClientSession, StdioServerParameters
-from mcp.client.stdio import stdio_client
from dspy.utils.mcp import convert_mcp_tool
+if importlib.util.find_spec("mcp") is None:
+ pytest.skip(reason="mcp is not installed", allow_module_level=True)
+
@pytest.mark.asyncio
async def test_convert_mcp_tool():
+ from mcp import ClientSession, StdioServerParameters
+ from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(
command="python",
args=["tests/utils/resources/mcp_server.py"],
diff --git a/uv.lock b/uv.lock
index fd41b9611..3860c2eb7 100644
--- a/uv.lock
+++ b/uv.lock
@@ -665,7 +665,7 @@ wheels = [
[[package]]
name = "dspy"
-version = "2.6.19"
+version = "2.6.24"
source = { editable = "." }
dependencies = [
{ name = "anyio" },
@@ -705,7 +705,6 @@ dev = [
{ name = "datamodel-code-generator" },
{ name = "litellm" },
{ name = "litellm", extra = ["proxy"], marker = "sys_platform != 'win32'" },
- { name = "mcp", marker = "python_full_version >= '3.10'" },
{ name = "pillow" },
{ name = "pre-commit" },
{ name = "pytest" },
@@ -716,6 +715,9 @@ dev = [
mcp = [
{ name = "mcp", marker = "python_full_version >= '3.10'" },
]
+test-extras = [
+ { name = "mcp", marker = "python_full_version >= '3.10'" },
+]
weaviate = [
{ name = "weaviate-client" },
]
@@ -739,8 +741,8 @@ requires-dist = [
{ name = "litellm", marker = "sys_platform == 'win32' and extra == 'dev'", specifier = ">=1.60.3" },
{ name = "litellm", extras = ["proxy"], marker = "sys_platform != 'win32' and extra == 'dev'", specifier = ">=1.60.3" },
{ name = "magicattr", specifier = ">=0.1.6" },
- { name = "mcp", marker = "python_full_version >= '3.10' and extra == 'dev'", specifier = ">=1.5.0" },
{ name = "mcp", marker = "python_full_version >= '3.10' and extra == 'mcp'" },
+ { name = "mcp", marker = "python_full_version >= '3.10' and extra == 'test-extras'" },
{ name = "numpy", marker = "python_full_version == '3.9.*'", specifier = ">=1.26.0,<2.2" },
{ name = "numpy", marker = "python_full_version >= '3.10'", specifier = ">=1.26.0" },
{ name = "openai", specifier = ">=0.28.1" },
@@ -761,7 +763,7 @@ requires-dist = [
{ name = "ujson", specifier = ">=5.8.0" },
{ name = "weaviate-client", marker = "extra == 'weaviate'", specifier = "~=4.5.4" },
]
-provides-extras = ["anthropic", "weaviate", "aws", "dev", "mcp"]
+provides-extras = ["anthropic", "weaviate", "aws", "dev", "mcp", "test-extras"]
[[package]]
name = "email-validator"