🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fix test_scrape_web_page proxy error
shenchuchengfba730390c36
diff --git a/tests/conftest.py b/tests/conftest.pyindex a15e3e85b..68a2ff596 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -112,7 +112,7 @@ def llm_api():logger.info("Tearing down the test")[email protected](scope="session")def proxy():pattern = re.compile(rb"(?P<method>[a-zA-Z]+) (?P<uri>(\w+://)?(?P<host>[^\s\'\"<>\[\]{}|/:]+)(:(?P<port>\d+))?[^\s\'\"<>\[\]{}|]*) "@@ -136,8 +136,11 @@ def proxy():remote_writer.write(data)await asyncio.gather(pipe(reader, remote_writer), pipe(remote_reader, writer))- server = asyncio.get_event_loop().run_until_complete(asyncio.start_server(handle_client, "127.0.0.1", 0))- return "http://{}:{}".format(*server.sockets[0].getsockname())+ async def proxy_func():+ server = await asyncio.start_server(handle_client, "127.0.0.1", 0)+ return server, "http://{}:{}".format(*server.sockets[0].getsockname())++ return proxy_func()# see https://github.com/Delgan/loguru/issues/59#issuecomment-466591978diff --git a/tests/metagpt/tools/test_web_browser_engine_playwright.py b/tests/metagpt/tools/test_web_browser_engine_playwright.pyindex 1e23ebb31..0f2679531 100644--- a/tests/metagpt/tools/test_web_browser_engine_playwright.py+++ b/tests/metagpt/tools/test_web_browser_engine_playwright.py@@ -13,9 +13,9 @@ from metagpt.utils.parse_html import WebPage@pytest.mark.parametrize("browser_type, use_proxy, kwagrs, url, urls",[- ("chromium", {"proxy": True}, {}, "https://deepwisdom.ai", ("https://deepwisdom.ai",)),- ("firefox", {}, {"ignore_https_errors": True}, "https://deepwisdom.ai", ("https://deepwisdom.ai",)),- ("webkit", {}, {"ignore_https_errors": True}, "https://deepwisdom.ai", ("https://deepwisdom.ai",)),+ ("chromium", {"proxy": True}, {}, "https://www.deepwisdom.ai", ("https://www.deepwisdom.ai",)),+ ("firefox", {}, {"ignore_https_errors": True}, "https://www.deepwisdom.ai", ("https://www.deepwisdom.ai",)),+ ("webkit", {}, {"ignore_https_errors": True}, "https://www.deepwisdom.ai", ("https://www.deepwisdom.ai",)),],ids=["chromium-normal", "firefox-normal", "webkit-normal"],)@@ -23,6 +23,7 @@ async def test_scrape_web_page(browser_type, use_proxy, kwagrs, url, urls, proxyglobal_proxy = CONFIG.global_proxytry:if use_proxy:+ server, proxy = await proxyCONFIG.global_proxy = proxybrowser = web_browser_engine_playwright.PlaywrightWrapper(browser_type=browser_type, **kwagrs)result = await browser.run(url)@@ -35,6 +36,7 @@ async def test_scrape_web_page(browser_type, use_proxy, kwagrs, url, urls, proxyassert len(results) == len(urls) + 1assert all(("MetaGPT" in i.inner_text) for i in results)if use_proxy:+ server.close()assert "Proxy:" in capfd.readouterr().outfinally:CONFIG.global_proxy = global_proxy