Test the retry logic in the scrape method.
(mock_playwright)
| 187 | |
| 188 | @pytest.mark.asyncio |
| 189 | async def test_scrape_method_retry_logic(mock_playwright): |
| 190 | """Test the retry logic in the scrape method.""" |
| 191 | mock_pw, mock_browser, mock_context, mock_page = mock_playwright |
| 192 | |
| 193 | url = "http://example.com" |
| 194 | loader = ChromiumLoader([url], backend="playwright", retry_limit=3) |
| 195 | |
| 196 | # Simulate two failures and then a success |
| 197 | mock_page.goto.side_effect = [asyncio.TimeoutError(), aiohttp.ClientError(), None] |
| 198 | mock_page.content.return_value = "<html>Success after retries</html>" |
| 199 | |
| 200 | result = await loader.scrape(url) |
| 201 | |
| 202 | assert "Success after retries" in result |
| 203 | assert mock_page.goto.call_count == 3 |
| 204 | assert mock_page.content.call_count == 1 |
| 205 | |
| 206 | # Test failure after all retries |
| 207 | mock_page.goto.side_effect = asyncio.TimeoutError() |
| 208 | |
| 209 | with pytest.raises(RuntimeError): |
| 210 | await loader.scrape(url) |
| 211 | |
| 212 | assert mock_page.goto.call_count == 6 # 3 more attempts |
| 213 | |
| 214 | |
| 215 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected