2020 ScraperAPIAmazonSearchToolInput ,
2121)
2222
23- # --- Fixtures ---
23+
24+ pytestmark = pytest .mark .allow_hosts ("127.0.0.1" )
2425
2526@pytest .fixture
2627def mock_env_api_key (monkeypatch ):
@@ -34,7 +35,6 @@ def scraper_api_wrapper(mock_env_api_key):
3435def scraper_api_structured_wrapper (mock_env_api_key ):
3536 return ScraperAPIStructuredWrapper ()
3637
37-
3838# --- Test ScraperAPIWrapper ---
3939
4040def test_scraper_api_wrapper_init_from_env (mock_env_api_key ):
@@ -126,8 +126,6 @@ def test_scraper_api_wrapper_scrape_connection_error(mock_get, scraper_api_wrapp
126126 )
127127
128128@pytest .mark .asyncio
129- @pytest .mark .allow_hosts (['127.0.0.1' , '::1' ]) # due to incompatibility between pytest-socket and asyncio
130- # https://github.com/pytest-dev/pytest-asyncio/issues/160
131129async def test_scraper_api_wrapper_scrape_async_success (scraper_api_wrapper ):
132130
133131 mock_response = AsyncMock ()
@@ -168,7 +166,7 @@ async def test_scraper_api_wrapper_scrape_async_success(scraper_api_wrapper):
168166 assert result == "<html>Async Success</html>"
169167
170168@pytest .mark .asyncio
171- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
169+
172170async def test_scraper_api_wrapper_scrape_async_with_params (scraper_api_wrapper ):
173171
174172 mock_response = AsyncMock ()
@@ -223,7 +221,7 @@ async def test_scraper_api_wrapper_scrape_async_with_params(scraper_api_wrapper)
223221 assert result == "Async Success Text"
224222
225223@pytest .mark .asyncio
226- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
224+
227225async def test_scraper_api_wrapper_scrape_async_http_error (scraper_api_wrapper ):
228226
229227 mock_response = AsyncMock (spec = aiohttp .ClientResponse )
@@ -328,7 +326,7 @@ def test_structured_wrapper_amazon_search(mock_get, scraper_api_structured_wrapp
328326
329327
330328@pytest .mark .asyncio
331- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
329+
332330async def test_structured_wrapper_google_search_async (scraper_api_structured_wrapper ):
333331
334332 mock_response = AsyncMock (spec = aiohttp .ClientResponse )
@@ -377,7 +375,7 @@ async def test_structured_wrapper_google_search_async(scraper_api_structured_wra
377375
378376
379377@pytest .mark .asyncio
380- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
378+
381379async def test_structured_wrapper_amazon_search_async (scraper_api_structured_wrapper ):
382380
383381 mock_response = AsyncMock (spec = aiohttp .ClientResponse )
@@ -461,7 +459,7 @@ def test_scraper_tool_run_error(mock_scrape, scraper_tool):
461459
462460
463461@pytest .mark .asyncio
464- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
462+
465463@patch .object (ScraperAPIWrapper , 'scrape_async' , new_callable = AsyncMock )
466464async def test_scraper_tool_arun (mock_scrape_async , scraper_tool ):
467465 mock_scrape_async .return_value = "Async scraped content"
@@ -482,7 +480,7 @@ async def test_scraper_tool_arun(mock_scrape_async, scraper_tool):
482480 assert result == "Async scraped content"
483481
484482@pytest .mark .asyncio
485- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
483+
486484@patch .object (ScraperAPIWrapper , 'scrape_async' , new_callable = AsyncMock )
487485async def test_scraper_tool_arun_error (mock_scrape_async , scraper_tool ):
488486 mock_scrape_async .side_effect = ConnectionError ("Async connection failed" )
@@ -541,7 +539,7 @@ def test_google_search_tool_run_error(mock_search, google_search_tool):
541539 mock_search .assert_called_once ()
542540
543541@pytest .mark .asyncio
544- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
542+
545543@patch .object (ScraperAPIStructuredWrapper , 'google_search_async' , new_callable = AsyncMock )
546544async def test_google_search_tool_arun (mock_search_async , google_search_tool ):
547545 mock_search_async .return_value = '{"async_google_data": "found"}'
@@ -566,7 +564,7 @@ async def test_google_search_tool_arun(mock_search_async, google_search_tool):
566564 assert result == '{"async_google_data": "found"}'
567565
568566@pytest .mark .asyncio
569- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
567+
570568@patch .object (ScraperAPIStructuredWrapper , 'google_search_async' , new_callable = AsyncMock )
571569async def test_google_search_tool_arun_error (mock_search_async , google_search_tool ):
572570 mock_search_async .side_effect = Exception ("Async Search failed" )
@@ -623,7 +621,7 @@ def test_amazon_search_tool_run_error(mock_search, amazon_search_tool):
623621 mock_search .assert_called_once ()
624622
625623@pytest .mark .asyncio
626- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
624+
627625@patch .object (ScraperAPIStructuredWrapper , 'amazon_search_async' , new_callable = AsyncMock )
628626async def test_amazon_search_tool_arun (mock_search_async , amazon_search_tool ):
629627 mock_search_async .return_value = '{"async_amazon_data": "found"}'
@@ -642,7 +640,7 @@ async def test_amazon_search_tool_arun(mock_search_async, amazon_search_tool):
642640 assert result == '{"async_amazon_data": "found"}'
643641
644642@pytest .mark .asyncio
645- @ pytest . mark . allow_hosts ([ '127.0.0.1' , '::1' ])
643+
646644@patch .object (ScraperAPIStructuredWrapper , 'amazon_search_async' , new_callable = AsyncMock )
647645async def test_amazon_search_tool_arun_error (mock_search_async , amazon_search_tool ):
648646 mock_search_async .side_effect = TimeoutError ("Amazon Timeout" )
0 commit comments