Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fix fixture scopes in tests

Nick Sweeting1f323150310f
diff --git a/tests/ci/test_browser_session_start.py b/tests/ci/test_browser_session_start.py
index 3139516c2..676d541b6 100644
--- a/tests/ci/test_browser_session_start.py
+++ b/tests/ci/test_browser_session_start.py
@@ -25,13 +25,13 @@ logger = logging.getLogger('browser_session_start_tests')
class TestBrowserSessionStart:
"""Tests for BrowserSession.start() method initialization and concurrency."""
- @pytest.fixture
+ @pytest.fixture(scope='module')
async def browser_profile(self):
"""Create and provide a BrowserProfile with headless mode."""
profile = BrowserProfile(headless=True, user_data_dir=None)
yield profile
- @pytest.fixture
+ @pytest.fixture(scope='function')
async def browser_session(self, browser_profile):
"""Create a BrowserSession instance without starting it."""
session = BrowserSession(browser_profile=browser_profile)
diff --git a/tests/ci/test_registry.py b/tests/ci/test_registry.py
index 5c1d29591..f5d87dbdf 100644
--- a/tests/ci/test_registry.py
+++ b/tests/ci/test_registry.py
@@ -83,7 +83,7 @@ def http_server():
server.stop()
[email protected](scope='module')
def base_url(http_server):
"""Return the base URL for the test HTTP server."""
return f'http://{http_server.host}:{http_server.port}'
@@ -101,19 +101,19 @@ async def browser_session():
await browser_session.stop()
[email protected](scope='module')
def mock_llm():
"""Create a mock LLM"""
return MockLLM()
[email protected](scope='function')
def registry():
"""Create a fresh registry for each test"""
return Registry[TestContext]()
[email protected](scope='module')
async def test_browser(base_url):
"""Create a real BrowserSession for testing"""
browser_session = BrowserSession(
@@ -121,7 +121,7 @@ async def test_browser(base_url):
user_data_dir=None,
)
await browser_session.start()
- # Navigate to test page
+ # Create tab and navigate to test page
await browser_session.create_new_tab(f'{base_url}/test')
yield browser_session
await browser_session.stop()