Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Enhance test model search and API key handling
Magnus Müller10de9663f2db
diff --git a/tests/conftest.py b/tests/conftest.pyindex 447dba533..663966c27 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -8,6 +8,7 @@ import sysimport pytestfrom langchain_openai import ChatOpenAI+from pydantic import SecretStr# Ensure the project root is in the Python pathsys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))@@ -35,7 +36,7 @@ def llm():api_key = os.getenv('OPENAI_API_KEY')logger.debug(f'API Key present: {bool(api_key)}')logger.debug('Using actual ChatOpenAI model')- return ChatOpenAI(model='gpt-4o', api_key=api_key)+ return ChatOpenAI(model='gpt-4o', api_key=SecretStr(api_key) if api_key else None)@pytest.fixture(scope='session')diff --git a/tests/test_models.py b/tests/test_models.pyindex cab2eaf6a..916e44c25 100644--- a/tests/test_models.py+++ b/tests/test_models.py@@ -47,6 +47,14 @@ api_key_anthropic = SecretStr(os.getenv('ANTHROPIC_API_KEY') or '')# pytest -s -v tests/test_models.py@pytest.fixture(params=[+ ChatOpenAI(model='gpt-4o'),+ ChatOpenAI(model='gpt-4o-mini'),+ AzureChatOpenAI(+ model='gpt-4o',+ api_version='2024-10-21',+ azure_endpoint=os.getenv('AZURE_OPENAI_ENDPOINT', ''),+ api_key=SecretStr(os.getenv('AZURE_OPENAI_KEY', '')),+ ),# run: ollama startChatOpenAI(base_url='https://api.deepseek.com/v1',@@ -70,14 +78,6 @@ api_key_anthropic = SecretStr(os.getenv('ANTHROPIC_API_KEY') or '')stop=None,api_key=api_key_anthropic,),- ChatOpenAI(model='gpt-4o'),- ChatOpenAI(model='gpt-4o-mini'),- AzureChatOpenAI(- model='gpt-4o',- api_version='2024-10-21',- azure_endpoint=os.getenv('AZURE_OPENAI_ENDPOINT', ''),- api_key=SecretStr(os.getenv('AZURE_OPENAI_KEY', '')),- ),ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=api_key_gemini),ChatGoogleGenerativeAI(model='gemini-1.5-pro', api_key=api_key_gemini),ChatGoogleGenerativeAI(model='gemini-1.5-flash-latest', api_key=api_key_gemini),@@ -88,13 +88,13 @@ api_key_anthropic = SecretStr(os.getenv('ANTHROPIC_API_KEY') or '')),],ids=[+ 'gpt-4o',+ 'gpt-4o-mini',+ 'azure-gpt-4o','deepseek-reasoner','qwen2.5:latest','azure-gpt-4o-mini','claude-3-5-sonnet',- 'gpt-4o',- 'gpt-4o-mini',- 'azure-gpt-4o','gemini-2.0-flash-exp','gemini-1.5-pro','gemini-1.5-flash-latest',@@ -138,9 +138,11 @@ async def test_model_search(llm, context):use_vision=use_vision,)history: AgentHistoryList = await agent.run(max_steps=2)+ done = history.is_done()+ successful = history.is_successful()action_names = history.action_names()print(f'Actions performed: {action_names}')- errors = history.errors()+ errors = [e for e in history.errors() if e is not None]errors = '\n'.join(errors)passed = Falseif 'search_google' in action_names:@@ -152,6 +154,6 @@ async def test_model_search(llm, context):else:passed = False- print(f'Model {model_name}: {"✅ PASSED" if passed else "❌ FAILED"}')+ print(f'Model {model_name}: {"✅ PASSED - " if passed else "❌ FAILED - "} Done: {done} Successful: {successful}')assert passed, f'Model {model_name} not working\nActions performed: {action_names}\nErrors: {errors}'