Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

fix(deno): Make deno tests optional for development but mandatory in CI (#9269)

Isaac Miller4dc14551402c
diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml
index d5cc4f1fb..43764fdf2 100644
--- a/.github/workflows/run_tests.yml
+++ b/.github/workflows/run_tests.yml
@@ -85,8 +85,8 @@ jobs:
run: uv run -p .venv pytest -vv 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
+ - name: Run extra and deno tests
+ run: uv run -p .venv pytest tests/ -m 'extra or deno' --extra --deno
llm_call_test:
name: Run Tests with Real LM
diff --git a/pyproject.toml b/pyproject.toml
index efcc4198c..dac255163 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -109,9 +109,6 @@ exclude_lines = [
]
[tool.pytest.ini_options]
-markers = [
- "integration: tests requiring external dependencies (Deno, LM)",
-]
filterwarnings = [
# litellm uses deprecated pydantic config classes sometimes.
# The issue has been fixed repeatedly, but still keeps showing up.
diff --git a/tests/conftest.py b/tests/conftest.py
index b634c8ac6..81680d970 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -5,7 +5,7 @@ import pytest
from tests.test_utils.server import litellm_test_server, read_litellm_test_server_request_logs # noqa: F401
-SKIP_DEFAULT_FLAGS = ["reliability", "extra", "llm_call"]
+SKIP_DEFAULT_FLAGS = ["reliability", "extra", "llm_call", "deno"]
@pytest.fixture(autouse=True)
@@ -44,7 +44,7 @@ def pytest_configure(config):
def pytest_collection_modifyitems(config, items):
for flag in SKIP_DEFAULT_FLAGS:
if config.getoption(f"--{flag}"):
- return
+ continue
skip_mark = pytest.mark.skip(reason=f"need --{flag} option to run")
for item in items:
diff --git a/tests/predict/test_code_act.py b/tests/predict/test_code_act.py
index 424656f8e..a268d9d85 100644
--- a/tests/predict/test_code_act.py
+++ b/tests/predict/test_code_act.py
@@ -1,5 +1,3 @@
-import shutil
-
import pytest
import dspy
@@ -7,11 +5,7 @@ from dspy import Signature
from dspy.predict import CodeAct
from dspy.utils import DummyLM
-# This test suite requires deno to be installed. Please install deno following https://docs.deno.com/runtime/getting_started/installation/
-is_deno_available = shutil.which("deno") is not None
-skip_if_deno_not_available = pytest.mark.skipif(
- not is_deno_available, reason="Deno is not installed or not in PATH"
-)
+pytestmark = pytest.mark.deno
class BasicQA(Signature):
@@ -22,7 +16,6 @@ def add(a: float, b: float) -> float:
"add two numbers"
return a + b
-@skip_if_deno_not_available
def test_codeact_code_generation():
lm = DummyLM(
[
@@ -54,7 +47,6 @@ def extract_maximum_minimum(input_list: str) -> dict[str, float]:
numbers = list(map(float, input_list.split(",")))
return {"maximum": max(numbers), "minimum": min(numbers)}
-@skip_if_deno_not_available
def test_codeact_support_multiple_fields():
lm = DummyLM(
[
@@ -78,7 +70,6 @@ def test_codeact_support_multiple_fields():
assert program.interpreter.deno_process is None
-@skip_if_deno_not_available
def test_codeact_code_parse_failure():
lm = DummyLM(
[
@@ -108,7 +99,6 @@ def test_codeact_code_parse_failure():
assert program.interpreter.deno_process is None
-@skip_if_deno_not_available
def test_codeact_code_execution_failure():
lm = DummyLM(
[
@@ -142,7 +132,6 @@ class CustomTool:
def __call__(self, a: float, b: float) -> float:
return a + b
-@skip_if_deno_not_available
def test_codeact_tool_validation():
with pytest.raises(ValueError, match="CodeAct only accepts functions and not callable objects."):
CodeAct(BasicQA, tools=[CustomTool()])
diff --git a/tests/predict/test_program_of_thought.py b/tests/predict/test_program_of_thought.py
index 72cf95502..525c1d492 100644
--- a/tests/predict/test_program_of_thought.py
+++ b/tests/predict/test_program_of_thought.py
@@ -1,4 +1,3 @@
-import shutil
from unittest.mock import patch
import pytest
@@ -7,16 +6,13 @@ import dspy
from dspy import ProgramOfThought, Signature
from dspy.utils import DummyLM
-# This test suite requires deno to be installed. Please install deno following https://docs.deno.com/runtime/getting_started/installation/
-is_deno_available = shutil.which("deno") is not None
-
class BasicQA(Signature):
question = dspy.InputField()
answer = dspy.OutputField(desc="often between 1 and 5 words")
[email protected](not is_deno_available, reason="Deno is not installed or not in PATH")
def test_pot_code_generation():
lm = DummyLM(
[
@@ -35,7 +31,7 @@ def test_pot_code_generation():
# This test ensures the old finetuned saved models still work
[email protected](not is_deno_available, reason="Deno is not installed or not in PATH")
def test_old_style_pot():
lm = DummyLM(
[
@@ -56,7 +52,7 @@ class ExtremumFinder(Signature):
minimum = dspy.OutputField(desc="The minimum of the given numbers")
[email protected](not is_deno_available, reason="Deno is not installed or not in PATH")
def test_pot_support_multiple_fields():
lm = DummyLM(
[
@@ -75,7 +71,7 @@ def test_pot_support_multiple_fields():
assert pot.interpreter.deno_process is None
[email protected](not is_deno_available, reason="Deno is not installed or not in PATH")
def test_pot_code_generation_with_one_error():
lm = DummyLM(
[
@@ -97,7 +93,7 @@ def test_pot_code_generation_with_one_error():
assert pot.interpreter.deno_process is None
[email protected](not is_deno_available, reason="Deno is not installed or not in PATH")
def test_pot_code_generation_persistent_errors():
max_iters = 3
lm = DummyLM(
@@ -114,7 +110,6 @@ def test_pot_code_generation_persistent_errors():
pot = ProgramOfThought(BasicQA, max_iters=max_iters)
with pytest.raises(RuntimeError, match="Max hops reached. Failed to run ProgramOfThought: ZeroDivisionError:"):
pot(question="What is 1+1?")
- assert pot.interpreter.deno_process is None
def test_pot_code_parse_error():
diff --git a/tests/predict/test_rlm.py b/tests/predict/test_rlm.py
index f2f25940c..3e54d3249 100644
--- a/tests/predict/test_rlm.py
+++ b/tests/predict/test_rlm.py
@@ -3,7 +3,7 @@ Tests for the RLM (Recursive Language Model) module.
Test organization:
- Unit tests (no Deno required): MockInterpreter, RLM formatting, signatures
-- Integration tests (@pytest.mark.integration): PythonInterpreter with Deno
+- Integration tests (@pytest.mark.deno): PythonInterpreter with Deno
"""
from contextlib import contextmanager
@@ -549,7 +549,7 @@ class TestRLMDynamicSignature:
# ============================================================================
class TestPythonInterpreter:
"""Integration tests for the secure sandbox with tool support."""
@@ -708,7 +708,7 @@ print(f"Count: {info['count']}")
interp.execute("undefined_variable")
class TestSandboxSecurity:
"""Integration tests for sandbox security restrictions."""
@@ -828,7 +828,7 @@ class TestRLMTypeCoercionMock:
# ============================================================================
class TestRLMTypeCoercion:
"""Tests for RLM type coercion through full forward pass with PythonInterpreter.
@@ -872,7 +872,7 @@ class TestRLMTypeCoercion:
# ============================================================================
class TestRLMMultipleOutputs:
"""Tests for signatures with multiple typed output fields.
@@ -959,7 +959,7 @@ class TestRLMMultipleOutputs:
# ============================================================================
class TestRLMWithDummyLM:
"""End-to-end tests using DummyLM with RLM and PythonInterpreter.
diff --git a/tests/primitives/test_python_interpreter.py b/tests/primitives/test_python_interpreter.py
index b8e21f45c..4a34b7f68 100644
--- a/tests/primitives/test_python_interpreter.py
+++ b/tests/primitives/test_python_interpreter.py
@@ -1,15 +1,12 @@
import os
import random
-import shutil
import pytest
from dspy.primitives.code_interpreter import CodeInterpreterError, FinalOutput
from dspy.primitives.python_interpreter import PythonInterpreter
-# This test suite requires deno to be installed. Please install deno following https://docs.deno.com/runtime/getting_started/installation/
-if shutil.which("deno") is None:
- pytest.skip(reason="Deno is not installed or not in PATH", allow_module_level=True)
+pytestmark = pytest.mark.deno
def test_execute_simple_code():