Skip to content

Commit 022ec55

Browse files
ci: enable integ tests for anthropic, cohere, mistral, openai, writer (#510)
1 parent 040ba21 commit 022ec55

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

tests_integ/conftest.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import json
2+
import logging
3+
import os
4+
5+
import boto3
16
import pytest
27

8+
logger = logging.getLogger(__name__)
9+
10+
11+
def pytest_sessionstart(session):
12+
_load_api_keys_from_secrets_manager()
13+
14+
315
## Data
416

517

@@ -28,3 +40,43 @@ async def alist(items):
2840
return [item async for item in items]
2941

3042
return alist
43+
44+
45+
## Models
46+
47+
48+
def _load_api_keys_from_secrets_manager():
49+
"""Load API keys as environment variables from AWS Secrets Manager."""
50+
session = boto3.session.Session()
51+
client = session.client(service_name="secretsmanager")
52+
if "STRANDS_TEST_API_KEYS_SECRET_NAME" in os.environ:
53+
try:
54+
secret_name = os.getenv("STRANDS_TEST_API_KEYS_SECRET_NAME")
55+
response = client.get_secret_value(SecretId=secret_name)
56+
57+
if "SecretString" in response:
58+
secret = json.loads(response["SecretString"])
59+
for key, value in secret.items():
60+
os.environ[f"{key.upper()}_API_KEY"] = str(value)
61+
62+
except Exception as e:
63+
logger.warning("Error retrieving secret", e)
64+
65+
"""
66+
Validate that required environment variables are set when running in GitHub Actions.
67+
This prevents tests from being unintentionally skipped due to missing credentials.
68+
"""
69+
if os.environ.get("GITHUB_ACTIONS") != "true":
70+
logger.warning("Tests running outside GitHub Actions, skipping required provider validation")
71+
return
72+
73+
required_providers = {
74+
"ANTHROPIC_API_KEY",
75+
"COHERE_API_KEY",
76+
"MISTRAL_API_KEY",
77+
"OPENAI_API_KEY",
78+
"WRITER_API_KEY",
79+
}
80+
for provider in required_providers:
81+
if provider not in os.environ or not os.environ[provider]:
82+
raise ValueError(f"Missing required environment variables for {provider}")

tests_integ/models/providers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ def __init__(self):
7272
bedrock = ProviderInfo(id="bedrock", factory=lambda: BedrockModel())
7373
cohere = ProviderInfo(
7474
id="cohere",
75-
environment_variable="CO_API_KEY",
75+
environment_variable="COHERE_API_KEY",
7676
factory=lambda: OpenAIModel(
7777
client_args={
7878
"base_url": "https://api.cohere.com/compatibility/v1",
79-
"api_key": os.getenv("CO_API_KEY"),
79+
"api_key": os.getenv("COHERE_API_KEY"),
8080
},
8181
model_id="command-a-03-2025",
8282
params={"stream_options": None},

tests_integ/models/conformance.py renamed to tests_integ/models/test_conformance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from strands.types.models import Model
3+
from strands.models import Model
44
from tests_integ.models.providers import ProviderInfo, all_providers
55

66

@@ -9,7 +9,7 @@ def get_models():
99
pytest.param(
1010
provider_info,
1111
id=provider_info.id, # Adds the provider name to the test name
12-
marks=[provider_info.mark], # ignores tests that don't have the requirements
12+
marks=provider_info.mark, # ignores tests that don't have the requirements
1313
)
1414
for provider_info in all_providers
1515
]

tests_integ/models/test_model_anthropic.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
import strands
77
from strands import Agent
88
from strands.models.anthropic import AnthropicModel
9-
from tests_integ.models import providers
109

11-
# these tests only run if we have the anthropic api key
12-
pytestmark = providers.anthropic.mark
10+
"""
11+
These tests only run if we have the anthropic api key
12+
13+
Because of infrequent burst usage, Anthropic tests are unreliable, failing tests with 529s.
14+
{'type': 'error', 'error': {'details': None, 'type': 'overloaded_error', 'message': 'Overloaded'}}
15+
https://docs.anthropic.com/en/api/errors#http-errors
16+
"""
17+
pytestmark = pytest.skip(
18+
"Because of infrequent burst usage, Anthropic tests are unreliable, failing with 529s", allow_module_level=True
19+
)
1320

1421

1522
@pytest.fixture

tests_integ/models/test_model_cohere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def model():
1616
return OpenAIModel(
1717
client_args={
1818
"base_url": "https://api.cohere.com/compatibility/v1",
19-
"api_key": os.getenv("CO_API_KEY"),
19+
"api_key": os.getenv("COHERE_API_KEY"),
2020
},
2121
model_id="command-a-03-2025",
2222
params={"stream_options": None},

0 commit comments

Comments
 (0)