From 97c2cbd11069d4cef4db37f7bd1d70e967af39e1 Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Wed, 15 Oct 2025 11:12:35 -0700 Subject: [PATCH] test: add fixture to mock ANTHROPIC_API_KEY for tests - Introduced a pytest fixture to automatically mock the ANTHROPIC_API_KEY environment variable for all tests in the test_anthropic.py module. - This change ensures that tests can run without requiring a real API key, improving test isolation and reliability. --- lib/crewai/tests/llms/anthropic/test_anthropic.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/crewai/tests/llms/anthropic/test_anthropic.py b/lib/crewai/tests/llms/anthropic/test_anthropic.py index 7d0780561..90a0eb766 100644 --- a/lib/crewai/tests/llms/anthropic/test_anthropic.py +++ b/lib/crewai/tests/llms/anthropic/test_anthropic.py @@ -5,11 +5,16 @@ from unittest.mock import patch, MagicMock import pytest from crewai.llm import LLM -from crewai.llms.providers.anthropic.completion import AnthropicCompletion from crewai.crew import Crew from crewai.agent import Agent from crewai.task import Task -from crewai.cli.constants import DEFAULT_LLM_MODEL + + +@pytest.fixture(autouse=True) +def mock_anthropic_api_key(): + """Automatically mock ANTHROPIC_API_KEY for all tests in this module.""" + with patch.dict(os.environ, {"ANTHROPIC_API_KEY": "test-key"}): + yield def test_anthropic_completion_is_used_when_anthropic_provider():