mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
test: Update test environment and VCR configuration
- Add mock_openai_key fixture for consistent test API key - Update VCR configuration to record API interactions - Update test cases to handle None and whitespace inputs Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -8,6 +8,11 @@ from dotenv import load_dotenv
|
|||||||
|
|
||||||
load_result = load_dotenv(override=True)
|
load_result = load_dotenv(override=True)
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def mock_openai_key(monkeypatch):
|
||||||
|
"""Mock OpenAI API key for VCR cassettes."""
|
||||||
|
monkeypatch.setenv("OPENAI_API_KEY", "sk-fake-test-key-12345")
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup_test_environment():
|
def setup_test_environment():
|
||||||
"""Set up test environment with a temporary directory for SQLite storage."""
|
"""Set up test environment with a temporary directory for SQLite storage."""
|
||||||
|
|||||||
@@ -317,15 +317,18 @@ def test_sync_task_execution():
|
|||||||
assert mock_execute_sync.call_count == len(tasks)
|
assert mock_execute_sync.call_count == len(tasks)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(
|
||||||
|
filter_headers=["authorization"],
|
||||||
|
record_mode="once"
|
||||||
|
)
|
||||||
@pytest.mark.parametrize("tool_output,expected", [
|
@pytest.mark.parametrize("tool_output,expected", [
|
||||||
("test result```", "test result"),
|
("test result```", "test result"),
|
||||||
("test result`", "test result"),
|
("test result`", "test result"),
|
||||||
("test result``````", "test result"),
|
("test result``````", "test result"),
|
||||||
("test result", "test result"),
|
("test result", "test result"),
|
||||||
("test ```result```", "test ```result"), # Only strip trailing backticks
|
("test ```result```", "test ```result"), # Only strip trailing backticks
|
||||||
(None, None), # Test non-string input
|
(None, "None"), # Test non-string input gets converted to string
|
||||||
("", ""), # Test empty string
|
(" ", " "), # Test whitespace string
|
||||||
("malformed`result```test", "malformed`result```test"), # Test non-trailing backticks
|
("malformed`result```test", "malformed`result```test"), # Test non-trailing backticks
|
||||||
])
|
])
|
||||||
def test_hierarchical_tool_output_formatting(tool_output, expected):
|
def test_hierarchical_tool_output_formatting(tool_output, expected):
|
||||||
|
|||||||
Reference in New Issue
Block a user