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
fix tests
Nick Sweeting875c8fc831d9
diff --git a/browser_use/config.py b/browser_use/config.pyindex 651fbcb80..156222f41 100644--- a/browser_use/config.py+++ b/browser_use/config.py@@ -62,7 +62,9 @@ class Config:@propertydef BROWSER_USE_CLOUD_UI_URL(self) -> str:url = os.getenv('BROWSER_USE_CLOUD_UI_URL', '')- assert '://' in url, 'BROWSER_USE_CLOUD_UI_URL must be a valid URL'+ # Allow empty string as default, only validate if set+ if url and '://' not in url:+ raise AssertionError('BROWSER_USE_CLOUD_UI_URL must be a valid URL if set')return url# Path configurationdiff --git a/tests/ci/test_sync_client_auth.py b/tests/ci/test_sync_client_auth.pyindex c9851254d..3dc9ff080 100644--- a/tests/ci/test_sync_client_auth.py+++ b/tests/ci/test_sync_client_auth.py@@ -6,7 +6,6 @@ import jsonimport tempfilefrom datetime import datetimefrom pathlib import Path-from unittest.mock import patchimport anyioimport httpx@@ -22,32 +21,21 @@ from bubus import BaseEventfrom browser_use.sync.auth import TEMP_USER_ID, DeviceAuthClientfrom browser_use.sync.service import CloudSync-# Define config dir for tests-# BROWSER_USE_CONFIG_DIR = Path.home() / ".config" / "browseruse"-BROWSER_USE_CONFIG_DIR = Path(tempfile.mkdtemp()) / '.config' / 'browseruse'+# Define config dir for tests - not needed anymore since we'll use env vars@pytest.fixture-def temp_config_dir():+def temp_config_dir(monkeypatch):"""Create temporary config directory."""with tempfile.TemporaryDirectory() as tmpdir:temp_dir = Path(tmpdir) / '.config' / 'browseruse'temp_dir.mkdir(parents=True, exist_ok=True)- # Temporarily replace the config dir- original = BROWSER_USE_CONFIG_DIR- import browser_use.sync.auth- import browser_use.utils-- browser_use.sync.auth.BROWSER_USE_CONFIG_DIR = temp_dir- browser_use.utils.BROWSER_USE_CONFIG_DIR = temp_dir+ # Use monkeypatch to set the environment variable+ monkeypatch.setenv('BROWSER_USE_CONFIG_DIR', str(temp_dir))yield temp_dir- # Restore original- browser_use.sync.auth.BROWSER_USE_CONFIG_DIR = original- browser_use.utils.BROWSER_USE_CONFIG_DIR = original-@pytest.fixtureasync def http_client(httpserver: HTTPServer):@@ -561,10 +549,8 @@ class TestCloudSync:content = '\n'.join(json.dumps(event) for event in events) + '\n'await anyio.Path(wal_path).write_text(content)- # Patch BROWSER_USE_CONFIG_DIR to point to our temp directory- with patch('browser_use.utils.BROWSER_USE_CONFIG_DIR', temp_config_dir):- # Call the method under test- await service._update_wal_user_ids(service.session_id)+ # Call the method under test (temp_config_dir fixture already sets the env var)+ await service._update_wal_user_ids(service.session_id)# Read back the updated file and verify changescontent = await anyio.Path(wal_path).read_text()