Skip to content

Fix flet test failing when the app under test starts slowly - #6995

Open
ndonkoHenri wants to merge 4 commits into
flet-1.1.0from
fix/flet-test-wait-for-app-6993
Open

ndonkoHenri wants to merge 4 commits into
flet-1.1.0from
fix/flet-test-wait-for-app-6993

Conversation

@ndonkoHenri

@ndonkoHenri ndonkoHenri commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6993.

On desktop (and mobile), flet test runs the app inside the Flutter test host on its embedded Python. runFletDeviceTest started the app, pumped a fixed 20 frames (~2 s), then connected the remote tester. When the app took longer than that to start, the test ran against a blank window. The first run after a build is that slow case, especially on Windows where antivirus scans the new bundle, so a freshly created project failed its own sample test.

The driver now pumps until Python sends a test-only test_ready page flag after main() finishes its initial updates (or after the first yield of a generator handler). Registration clears isLoading before main() runs, so registration alone does not unblock the tester. Empty apps also signal readiness. The driver times out after 2 minutes with a clear message and fails with the app's startup error if the backend reports one.

Testing

Automated follow-up validation after merging the current flet-1.1.0 target:

  • Python unit suite: 443 passed, 9 skipped, including delayed initialization, empty apps, startup failures, and sync/async generator handlers.
  • Flutter startup regression tests: 5 passed, covering rendered readiness, empty apps, startup errors, and timeouts.
  • Confirmed the delayed-start Flutter regression fails with the original registration-only readiness condition.
  • Flutter analysis, Python lint/format checks, and commit hooks passed.

Full device builds were not rerun for the readiness follow-up. Original manual validation of the initial driver change:

Reproduced on Flet 1.0.5 with the flet create counter project, then ran the same project against the patched driver (via [tool.flet.flutter.pubspec.dev_dependencies]):

Where Scenario Stock driver Patched driver
macOS normal project passes passes
macOS time.sleep(5) at the top of main.py fails as reported (assert 0 == 1) passes
Windows 11 VM first cold run of an untouched project fails as reported passes (build/ deleted first)
Windows 11 VM warm rerun passes passes

The time.sleep(5) variant makes the race reproducible on any OS. flutter analyze on flet_integration_test is clean.

Summary by Sourcery

Ensure device-mode Flet tests synchronize with application startup before executing remote test commands.

Bug Fixes:

  • Make flet test wait for the app’s first page to finish initializing before connecting the remote tester, preventing failures for slow-starting applications.
  • Report application startup errors and timeout failures clearly instead of running tests against an uninitialized app.

Enhancements:

  • Add readiness signaling for test-mode sessions, including empty and generator-based applications.

Tests:

  • Add Flutter and Python coverage for delayed startup, readiness signaling, startup errors, timeouts, empty apps, and generator-based apps.

The device-mode test driver pumped a fixed 20 frames (~2 s) after starting
the app, then connected the remote tester. When the embedded Python app took
longer to start, as on the first run after a build (antivirus scanning the
new bundle on Windows), the test ran against a blank window.

Pump until FletBackend reports the first page loaded instead, with a
2-minute timeout, and fail with the app's startup error if it reports one.

Fixes #6993
@ndonkoHenri
ndonkoHenri requested review from FeodorFitsner and a balanced review from Copilot October 23, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@ndonkoHenri
ndonkoHenri requested a balanced review from Copilot October 23, 2026 21:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 99ff465
Status: ✅  Deploy successful!
Preview URL: https://7658766d.flet-website-v2.pages.dev
Branch Preview URL: https://fix-flet-test-wait-for-app-6.flet-website-v2.pages.dev

View logs

@ndonkoHenri ndonkoHenri linked an issue Oct 23, 2026 that may be closed by this pull request
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: flet test on freshly created project fails on Windows with an empty window

3 participants