diff --git a/tests/conftest.py b/tests/conftest.py index 262a7e9f1..f4db8f1f5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -257,8 +257,8 @@ async def start(): await runner.setup() site = aiohttp.web.TCPSite(runner, "localhost", 0) await site.start() - host, port = site._server.sockets[0].getsockname() - return site, f"http://{host}:{port}" + port = site._server.sockets[0].getsockname()[1] + return site, f"http://127.0.0.1:{port}" return start diff --git a/tests/metagpt/tools/test_web_browser_engine.py b/tests/metagpt/tools/test_web_browser_engine.py index 5620c8080..7a344e0ad 100644 --- a/tests/metagpt/tools/test_web_browser_engine.py +++ b/tests/metagpt/tools/test_web_browser_engine.py @@ -9,10 +9,10 @@ @pytest.mark.asyncio @pytest.mark.parametrize( - "browser_type,", + "browser_type", [ - (WebBrowserEngineType.PLAYWRIGHT,), - (WebBrowserEngineType.SELENIUM,), + WebBrowserEngineType.PLAYWRIGHT, + WebBrowserEngineType.SELENIUM, ], ids=["playwright", "selenium"], ) diff --git a/tests/metagpt/tools/test_web_browser_engine_playwright.py b/tests/metagpt/tools/test_web_browser_engine_playwright.py index f8ea6ae0e..12ea96d7b 100644 --- a/tests/metagpt/tools/test_web_browser_engine_playwright.py +++ b/tests/metagpt/tools/test_web_browser_engine_playwright.py @@ -42,7 +42,8 @@ async def test_scrape_web_page(browser_type, use_proxy, kwagrs, proxy, capfd, ht assert len(results) == len(urls) + 1 assert all(("MetaGPT" in i.inner_text) for i in results) if use_proxy: - await proxy_server.close() + proxy_server.close() + await proxy_server.wait_closed() assert "Proxy:" in capfd.readouterr().out await server.stop() diff --git a/tests/metagpt/tools/test_web_browser_engine_selenium.py b/tests/metagpt/tools/test_web_browser_engine_selenium.py index 7f0b8bd55..1b6a73678 100644 --- a/tests/metagpt/tools/test_web_browser_engine_selenium.py +++ b/tests/metagpt/tools/test_web_browser_engine_selenium.py @@ -43,13 +43,13 @@ async def test_scrape_web_page(browser_type, use_proxy, proxy, capfd, http_serve assert isinstance(result, WebPage) assert "MetaGPT" in result.inner_text - if urls: - results = await browser.run(url, *urls) - assert isinstance(results, list) - assert len(results) == len(urls) + 1 - assert all(("MetaGPT" in i.inner_text) for i in results) + results = await browser.run(url, *urls) + assert isinstance(results, list) + assert len(results) == len(urls) + 1 + assert all(("MetaGPT" in i.inner_text) for i in results) if use_proxy: - await proxy_server.close() + proxy_server.close() + await proxy_server.wait_closed() assert "Proxy:" in capfd.readouterr().out await server.stop()