From c85f6ab646906116f49bf677a8bc7777e0991af7 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 20 May 2026 11:58:28 +0200 Subject: [PATCH 1/2] test: Harden e2e templates test against transient apify-cli flakes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add `@pytest.mark.flaky(reruns=3)` to `test_static_crawler_actor_at_apify` and `timeout=120/600` to the apify-cli `subprocess.run` calls. A scheduled run today had a `playwright_chrome+impit+pip` variant hang on `apify push` for the full 30 min pytest-timeout window. The timeout makes a hung CLI fail fast; the reruns absorb the resulting transient. - Fix `rerun=` → `reruns=` kwarg typo in five existing `@pytest.mark.flaky` decorators. `pytest-rerunfailures` reads `reruns` (plural); the typo silently fell back to 1 retry instead of 3. --- .../test_static_crawlers_templates.py | 16 ++++++++++++++-- tests/unit/browsers/test_browser_pool.py | 2 +- .../test_stagehand_browser_controller.py | 2 +- .../test_adaptive_playwright_crawler.py | 6 +++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/e2e/project_template/test_static_crawlers_templates.py b/tests/e2e/project_template/test_static_crawlers_templates.py index 9486cba921..fc90b2ca89 100644 --- a/tests/e2e/project_template/test_static_crawlers_templates.py +++ b/tests/e2e/project_template/test_static_crawlers_templates.py @@ -47,6 +47,10 @@ pytest.param('poetry', marks=pytest.mark.poetry), ], ) +@pytest.mark.flaky( + reruns=3, + reason='`apify push` occasionally hangs against the Apify platform; retries cover transient CLI/network flakes.', +) async def test_static_crawler_actor_at_apify( tmp_path: Path, crawlee_wheel_path: Path, @@ -80,14 +84,21 @@ async def test_static_crawler_actor_at_apify( # Print apify version for debugging purposes in rare cases of CLI failures subprocess.run(['apify', '--version'], check=True) # noqa: ASYNC221, S607 - # Build actor using sequence of cli commands as the user would + # Build actor using sequence of cli commands as the user would. subprocess.run( # noqa: ASYNC221, S603 ['apify', 'login', '-t', os.environ['APIFY_TEST_USER_API_TOKEN']], # noqa: S607 capture_output=True, check=True, cwd=tmp_path / actor_name, + timeout=120, + ) + subprocess.run( # noqa: ASYNC221, S603 + ['apify', 'init', '-y', actor_name], # noqa: S607 + capture_output=True, + check=True, + cwd=tmp_path / actor_name, + timeout=120, ) - subprocess.run(['apify', 'init', '-y', actor_name], capture_output=True, check=True, cwd=tmp_path / actor_name) # noqa: ASYNC221, S603, S607 build_process = subprocess.run( # noqa: ASYNC221 ['apify', 'push'], # noqa: S607 @@ -97,6 +108,7 @@ async def test_static_crawler_actor_at_apify( # Prevent git from walking up into the surrounding project's .git/ when running under # a basetemp inside the repo (see --basetemp in the e2e-templates-tests poe task). env={**os.environ, 'GIT_CEILING_DIRECTORIES': str(tmp_path)}, + timeout=600, ) # Get actor ID from build log actor_id_regexp = re.compile(r'https:\/\/console\.apify\.com\/actors\/(.*)#\/builds\/\d*\.\d*\.\d*') diff --git a/tests/unit/browsers/test_browser_pool.py b/tests/unit/browsers/test_browser_pool.py index 15990cfec1..f04530a609 100644 --- a/tests/unit/browsers/test_browser_pool.py +++ b/tests/unit/browsers/test_browser_pool.py @@ -74,7 +74,7 @@ async def test_multiple_plugins_new_page_creation(server_url: URL) -> None: @pytest.mark.flaky( - rerun=3, + reruns=3, reason='Test is flaky on Windows and MacOS, see https://github.com/apify/crawlee-python/issues/1660.', ) async def test_new_page_with_each_plugin(server_url: URL) -> None: diff --git a/tests/unit/browsers/test_stagehand_browser_controller.py b/tests/unit/browsers/test_stagehand_browser_controller.py index 3139913477..effc5cd7b5 100644 --- a/tests/unit/browsers/test_stagehand_browser_controller.py +++ b/tests/unit/browsers/test_stagehand_browser_controller.py @@ -342,7 +342,7 @@ async def test_proxy_set_browserbase( @pytest.mark.flaky( - rerun=3, + reruns=3, reason='Test is flaky on Windows when Playwright hits net::ERR_NO_BUFFER_SPACE under xdist load.', ) async def test_fingerprint_headers_set_on_new_page(controller: StagehandBrowserController, server_url: URL) -> None: 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 119bc5e8ea..e36c95dde0 100644 --- a/tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py +++ b/tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py @@ -238,7 +238,7 @@ async def request_handler(context: AdaptivePlaywrightCrawlingContext) -> None: @pytest.mark.flaky( - rerun=3, + reruns=3, reason='Test is flaky on Windows when Playwright hits net::ERR_NO_BUFFER_SPACE and retries, ' 'causing the pre-nav hook to fire one extra time.', ) @@ -637,7 +637,7 @@ async def request_handler(context: AdaptivePlaywrightCrawlingContext) -> None: @pytest.mark.flaky( - rerun=3, + reruns=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: @@ -683,7 +683,7 @@ async def request_handler(context: AdaptivePlaywrightCrawlingContext) -> None: @pytest.mark.flaky( - rerun=3, + reruns=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_parsel(test_urls: list[str]) -> None: From 7db038b216b2d8a8f841fae07f5c231dec1044e2 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 20 May 2026 12:01:01 +0200 Subject: [PATCH 2/2] test: Lower `apify push` subprocess timeout from 600s to 120s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Match the timeout used for `apify login` / `apify init`. A healthy `apify push` finishes in 2–3 minutes; 120s leaves headroom for normal builds while making a hang fail much sooner. --- tests/e2e/project_template/test_static_crawlers_templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/project_template/test_static_crawlers_templates.py b/tests/e2e/project_template/test_static_crawlers_templates.py index fc90b2ca89..f50107a8a9 100644 --- a/tests/e2e/project_template/test_static_crawlers_templates.py +++ b/tests/e2e/project_template/test_static_crawlers_templates.py @@ -108,7 +108,7 @@ async def test_static_crawler_actor_at_apify( # Prevent git from walking up into the surrounding project's .git/ when running under # a basetemp inside the repo (see --basetemp in the e2e-templates-tests poe task). env={**os.environ, 'GIT_CEILING_DIRECTORIES': str(tmp_path)}, - timeout=600, + timeout=120, ) # Get actor ID from build log actor_id_regexp = re.compile(r'https:\/\/console\.apify\.com\/actors\/(.*)#\/builds\/\d*\.\d*\.\d*')