From f1dc78f8ffc187fe075de7d3ae25c0b60fdd8ecc Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 15 Apr 2026 14:43:37 +0200 Subject: [PATCH] test: Fix flaky tests in adaptive crawler and sitemap loader Add @pytest.mark.flaky(rerun=3) to test_adaptive_context_query_selector_beautiful_soup matching the parsel variant. Increase timeout in test_data_persistence_for_sitemap_loading from 2s to 10s to avoid TimeoutError on Windows CI with httpx. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../_adaptive_playwright/test_adaptive_playwright_crawler.py | 4 ++++ tests/unit/request_loaders/test_sitemap_request_loader.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py b/tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py index 8aed535c8a..ed337f36f8 100644 --- a/tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py +++ b/tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py @@ -631,6 +631,10 @@ async def request_handler(context: AdaptivePlaywrightCrawlingContext) -> None: mocked_browser_handler.assert_called_once_with() +@pytest.mark.flaky( + rerun=3, + reason='Test is flaky on Windows and MacOS, see https://github.com/apify/crawlee-python/issues/1650.', +) async def test_adaptive_context_query_selector_beautiful_soup(test_urls: list[str]) -> None: """Test that `context.query_selector_one` works regardless of the crawl type for BeautifulSoup variant. diff --git a/tests/unit/request_loaders/test_sitemap_request_loader.py b/tests/unit/request_loaders/test_sitemap_request_loader.py index 8033211157..d3742dfd6f 100644 --- a/tests/unit/request_loaders/test_sitemap_request_loader.py +++ b/tests/unit/request_loaders/test_sitemap_request_loader.py @@ -144,7 +144,7 @@ async def wait_for_sitemap_loader_not_empty(sitemap_loader: SitemapRequestLoader sitemap_loader = SitemapRequestLoader([str(sitemap_url)], http_client=http_client, persist_state_key=persist_key) # Give time to load - await asyncio.wait_for(wait_for_sitemap_loader_not_empty(sitemap_loader), timeout=2) + await asyncio.wait_for(wait_for_sitemap_loader_not_empty(sitemap_loader), timeout=10) await sitemap_loader.close()