Create flet control integration tests

From flet-dev/flet · View interactive version

Create flet control integration tests is an AI agent skill from the GitHub repository flet-dev/flet. Use when asked to create or update integration tests for any Flet control in sdk/python/packages/flet/integration_tests, including visual goldens and interactive behavior tests.

How to use this skill

Skill file

When to use

Use this skill when adding, updating, or reviewing integration tests for a Flet control (core, material, cupertino, theme, services, types, or examples).

Use it for:

Test placement

Pick the closest existing suite first:

Prefer adding tests to an existing file for the same control. Create a new test file only when no suitable file exists.

One file per control

Keep all tests for a control in test_<control>.py, whatever their scope. Module-scoped (flet_app) and function-scoped (flet_app_function) tests can share the file; pytest-asyncio runs each on its own event loop.

Fixture choice

Use fixtures from integration_tests/conftest.py:

Authoring workflow

  1. Identify behavior to verify.
  2. Build deterministic layout/state:
  1. Choose the fixture: flet_app unless the test needs a fresh app.
  2. Write test using async pytest.
  3. Use screenshot assertion for UI behavior, functional assertion for non-visual behavior.
  4. Name test so request.node.name can be used as screenshot key.
  5. Run target test file.
  6. If expected visuals changed, regenerate goldens with FLET_TEST_GOLDEN=1 (or FLET_TEST_GOLDEN=failed to overwrite only mismatching ones) and re-run without golden mode.

Assertion patterns

Visual control assertion

await flet_app.assert_control_screenshot(
    request.node.name,
    control,
)

Visual full-page assertion

flet_app_function.assert_screenshot(
    request.node.name,
    await flet_app_function.page.take_screenshot(
        pixel_ratio=flet_app_function.screenshots_pixel_ratio
    ),
)

Functional assertion

finder = await flet_app_function.tester.find_by_tooltip("Info tooltip")
assert finder.count == 1

Minimal template

A test_<control>.py file with one test of each scope:

import pytest

import flet as ft
import flet.testing as ftt


@pytest.mark.asyncio(loop_scope="module")
async def test_<behavior>(flet_app: ftt.FletTestApp, request):
    flet_app.page.theme_mode = ft.ThemeMode.LIGHT
    await flet_app.assert_control_screenshot(
        request.node.name,
        ft.Container(width=240, height=80, alignment=ft.Alignment.CENTER),
    )


@pytest.mark.asyncio(loop_scope="function")
async def test_<other_behavior>(flet_app_function: ftt.FletTestApp):
    flet_app_function.page.add(ft.IconButton(icon=ft.Icons.INFO, tooltip="Info"))
    await flet_app_function.tester.pump_and_settle()

    finder = await flet_app_function.tester.find_by_tooltip("Info")
    assert finder.count == 1

Run commands

Run one test file:

uv run pytest -s -o log_cli=true -o log_cli_level=INFO packages/flet/integration_tests/controls/core/test_control.py

Run a subset:

uv run pytest -s -o log_cli=true -o log_cli_level=INFO packages/flet/integration_tests/controls/core/test_control.py -k test_visible

Generate or update goldens:

FLET_TEST_GOLDEN=1 uv run pytest -s -o log_cli=true -o log_cli_level=INFO packages/flet/integration_tests/controls/core/test_control.py

Quality checklist

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.