test: Harden e2e templates test against transient apify-cli flakes#1905
Merged
Conversation
- 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.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1905 +/- ##
==========================================
- Coverage 92.95% 92.88% -0.07%
==========================================
Files 167 167
Lines 11709 11709
==========================================
- Hits 10884 10876 -8
- Misses 825 833 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
vdusek
added a commit
that referenced
this pull request
May 21, 2026
…h when sandbox is disabled (#1906) ## Summary The scheduled e2e tests for the Stagehand template have failed for several days. After PR #1900 fixed the `OPENAI_API_KEY` propagation, the next layer of failure surfaced — every Stagehand variant in [today's run](https://github.com/apify/crawlee-python/actions/runs/26136278735) failed identically on the Apify platform with: ``` stagehand.InternalServerError: Error code: 500 - {'success': False, 'message': 'connect ECONNREFUSED 127.0.0.1:<port>'} ``` ## Root cause Reproduced locally inside the `apify/actor-python-playwright:3.13` image: Stagehand's `BrowserLaunchOptions` accepts a `chromium_sandbox` field, but the field is **not propagated** to the underlying Chromium launch. When the actor runs as root (which it does on Apify), Chromium silently refuses to start because the setuid sandbox can't initialise — and Stagehand's local SEA server then hits `ECONNREFUSED` when it tries to connect to the missing Chromium CDP port. The regular `PlaywrightCrawler` is unaffected because Playwright's Python binding *does* translate `chromium_sandbox=False` into `--no-sandbox`. ## Fix In `StagehandBrowserPlugin`, when the sandbox is disabled (`config.disable_browser_sandbox=True`, which Apify auto-sets), append `'--no-sandbox'` to `browser_launch_options['args']` as an explicit workaround. Verified end-to-end in the same actor base image — the crawler now completes requests successfully. The `apify push` hang from the same scheduled run is a separate flake and is addressed in #1905.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Today's scheduled run had the
playwright_chrome+impit+pipvariant oftest_static_crawler_actor_at_apifyhang onapify pushfor the full 30-minutepytest-timeoutwindow (job log). Yesterday it was a different combination — these are transientapify-cli/ network flakes, not a code bug.Two test-infrastructure fixes:
@pytest.mark.flaky(reruns=3)ontest_static_crawler_actor_at_apify, plustimeout=120on everyapify-clisubprocess.run(login,init,push). A hung CLI now fails fast instead of burning the whole pytest-timeout window; the reruns absorb the transient.rerun=→reruns=kwarg typo in five existing@pytest.mark.flakydecorators.pytest-rerunfailuresreadsreruns(plural) — the typo silently meant 1 retry instead of 3 for the affected unit tests.The Stagehand
ECONNREFUSEDfailures from the same scheduled run are a separate bug, fixed in #1906.