Skip to content

Commit 4b41961

Browse files
fix broken tests (#706)
1 parent 3ee1710 commit 4b41961

6 files changed

Lines changed: 43 additions & 19 deletions

File tree

‎tests/code_executor/test_code_execution.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def code_output(self, row, exec_output):
3232
@pytest.mark.asyncio
3333
async def test_simple_code_execution_ray():
3434
"""Test simple code execution with basic input/output."""
35+
pytest.importorskip("ray")
3536

3637
# Initialize backend
3738
class TestCodeExecutor(curator.CodeExecutor):

‎tests/conftest.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from datasets import Dataset
88

99
os.environ["TELEMETRY_ENABLED"] = "false"
10+
os.environ["CURATOR_VIEWER"] = "false"
1011
mode = os.environ.get("VCR_MODE", None)
1112
_KEY_MAP = {
1213
"openai": "OPENAI_API_KEY",
@@ -16,6 +17,10 @@
1617
"vllm": "VLLM_API_KEY",
1718
"gemini": "GEMINI_API_KEY",
1819
}
20+
# Map backend names to directory names (to avoid namespace collisions with packages)
21+
_DIR_MAP = {
22+
"vllm": "vllm_backend",
23+
}
1924

2025

2126
@pytest.fixture
@@ -26,16 +31,18 @@ def temp_working_dir(request):
2631
os.environ[_KEY_MAP[backend.split("/")[-1]]] = "sk-mocked-**"
2732
backend = backend.split("/")[0]
2833
os.environ["HF_DATASETS_CACHE"] = "/dev/null"
29-
temp_working_dir = f"tests/integrations/{backend}/fixtures/.test_cache"
34+
# Use directory mapping to avoid namespace collisions with installed packages
35+
backend_dir = _DIR_MAP.get(backend, backend)
36+
temp_working_dir = f"tests/integrations/{backend_dir}/fixtures/.test_cache"
3037

3138
if cached_working_dir:
32-
working_dir_zip = f"tests/integrations/{backend}/fixtures/.test_cache.zip"
39+
working_dir_zip = f"tests/integrations/{backend_dir}/fixtures/.test_cache.zip"
3340
with zipfile.ZipFile(working_dir_zip, "r") as zip_ref:
3441
zip_ref.extractall(os.path.split(temp_working_dir)[0])
3542

3643
vcr_path = request.param.get("vcr_path", None)
3744
if not vcr_path:
38-
vcr_path = f"tests/integrations/{backend}/fixtures"
45+
vcr_path = f"tests/integrations/{backend_dir}/fixtures"
3946

4047
vcr_config = vcr.VCR(
4148
serializer="yaml",

‎tests/integrations/test_all.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,14 @@ def test_failed_requests_file_in_cache(temp_working_dir, mock_dataset):
565565
@pytest.mark.parametrize("temp_working_dir", ([{"integration": "vllm"}]), indirect=True)
566566
def test_basic_offline(temp_working_dir, mock_dataset):
567567
"""Test basic completion with VLLM backend"""
568+
pytest.importorskip("vllm")
568569
temp_working_dir, _, _ = temp_working_dir
569570

570571
import json
571572
import os
572573

573574
# Load mock responses from fixture file
574-
fixture_path = os.path.join(os.path.dirname(__file__), "vllm", "fixtures", "basic_responses.json")
575+
fixture_path = os.path.join(os.path.dirname(__file__), "vllm_backend", "fixtures", "basic_responses.json")
575576
with open(fixture_path) as f:
576577
mock_responses = json.load(f)
577578

‎tests/integrations/test_push_to_viewer.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import os
22

3+
import pytest
34
import vcr
45

56
from bespokelabs.curator.utils import load_dataset, push_to_viewer
67

78

9+
@pytest.fixture(autouse=True)
10+
def reset_curator_viewer_env():
11+
"""Reset CURATOR_VIEWER to false after each test to avoid affecting other tests."""
12+
original_value = os.environ.get("CURATOR_VIEWER")
13+
yield
14+
if original_value is not None:
15+
os.environ["CURATOR_VIEWER"] = original_value
16+
else:
17+
os.environ.pop("CURATOR_VIEWER", None)
18+
19+
820
def test_smoke(mock_dataset):
921
vcr_path = "tests/integrations/common_fixtures"
1022
os.environ["CURATOR_VIEWER"] = "true"

tests/integrations/vllm/fixtures/basic_responses.json renamed to tests/integrations/vllm_backend/fixtures/basic_responses.json

File renamed without changes.

‎tests/unittests/test_caching.py‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,26 @@ def test_disable_cache(tmp_path, temp_working_dir):
191191

192192
os.environ["CURATOR_DISABLE_CACHE"] = "true"
193193

194-
prompter = curator.LLM(model_name="gpt-4o-mini")
194+
try:
195+
prompter = curator.LLM(model_name="gpt-4o-mini")
195196

196-
# Run twice and store results
197-
with vcr_config.use_cassette("basic_diff_cache.yaml"):
198-
result1 = prompter(["Say '1'. Do not explain."], working_dir=str(tmp_path)).dataset
197+
# Run twice and store results
198+
with vcr_config.use_cassette("basic_diff_cache.yaml"):
199+
result1 = prompter(["Say '1'. Do not explain."], working_dir=str(tmp_path)).dataset
199200

200-
with vcr_config.use_cassette("basic_diff_cache.yaml"):
201-
result2 = prompter(["Say '1'. Do not explain."], working_dir=str(tmp_path)).dataset
201+
with vcr_config.use_cassette("basic_diff_cache.yaml"):
202+
result2 = prompter(["Say '1'. Do not explain."], working_dir=str(tmp_path)).dataset
202203

203-
# Verify both runs produced the expected output
204-
assert result1.to_pandas().iloc[0]["response"] == "1"
205-
assert result2.to_pandas().iloc[0]["response"] == "1"
204+
# Verify both runs produced the expected output
205+
assert result1.to_pandas().iloc[0]["response"] == "1"
206+
assert result2.to_pandas().iloc[0]["response"] == "1"
206207

207-
# Check cache directory, excluding metadata.db
208-
cache_dirs = [d for d in tmp_path.glob("*") if d.name != "metadata.db"]
208+
# Check cache directory, excluding metadata.db
209+
cache_dirs = [d for d in tmp_path.glob("*") if d.name != "metadata.db"]
209210

210-
# Should have exactly 2 different cache directories
211-
assert len(cache_dirs) == 2
212-
# All directories should be different (no duplicates)
213-
assert len({str(d) for d in cache_dirs}) == 2
211+
# Should have exactly 2 different cache directories
212+
assert len(cache_dirs) == 2
213+
# All directories should be different (no duplicates)
214+
assert len({str(d) for d in cache_dirs}) == 2
215+
finally:
216+
os.environ.pop("CURATOR_DISABLE_CACHE", None)

0 commit comments

Comments
 (0)