Skip to content

Commit 3e4eee0

Browse files
committed
test(flet-test): simplify counter test to plain pump_and_settle + assert
Drop the _find_text_when_ready polling helper. It was a band-aid for the android render race, but the real cause was the serious_python x86_64 crash (PR #218) — now fixed. Try the plain template-style test and let CI confirm the counter renders in time on the slow emulator.
1 parent 540961a commit 3e4eee0

1 file changed

Lines changed: 8 additions & 29 deletions

File tree

  • sdk/python/examples/apps/flet_test_counter/tests
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
1-
import asyncio
2-
import contextlib
3-
import time
4-
51
import flet.testing as ftt
62

73

8-
async def _find_text_when_ready(tester, text: str, timeout: float = 60.0):
9-
"""
10-
Pump-and-retry (up to `timeout` seconds) until a control with `text` appears.
11-
12-
On a device the app runs embedded Python over dart_bridge; its cold start
13-
(interpreter init + `import flet` + running `main()`) can take tens of
14-
seconds on a slow CI emulator, so the first python-driven frame may land
15-
well after the device driver's fixed warmup. `pump_and_settle` only settles
16-
Flutter frames — it can't know a python -> dart round-trip is still in
17-
flight — so poll rather than assert on the first frame.
18-
"""
19-
deadline = time.monotonic() + timeout
20-
while True:
21-
finder = await tester.find_by_text(text)
22-
if finder.count >= 1 or time.monotonic() >= deadline:
23-
return finder
24-
await asyncio.sleep(0.25)
25-
with contextlib.suppress(TimeoutError):
26-
await tester.pump_and_settle()
27-
28-
294
async def test_counter(flet_app: ftt.FletTestApp):
305
tester = flet_app.tester
316

32-
# Initial state (wait for the app's first render).
33-
assert (await _find_text_when_ready(tester, "0")).count == 1
7+
await tester.pump_and_settle()
8+
9+
# Initial state
10+
assert (await tester.find_by_text("0")).count == 1
3411

3512
# Increment once
3613
await tester.tap(await tester.find_by_key("increment"))
37-
assert (await _find_text_when_ready(tester, "1")).count == 1
14+
await tester.pump_and_settle()
15+
assert (await tester.find_by_text("1")).count == 1
3816

3917
# Decrement twice -> -1
4018
await tester.tap(await tester.find_by_key("decrement"))
4119
await tester.tap(await tester.find_by_key("decrement"))
42-
assert (await _find_text_when_ready(tester, "-1")).count == 1
20+
await tester.pump_and_settle()
21+
assert (await tester.find_by_text("-1")).count == 1

0 commit comments

Comments
 (0)