CtrlK
BlogDocsLog inGet started
Tessl Logo

testland/flagsmith-testing

Wraps Flagsmith server-side SDK testing patterns (feature flags / feature toggles) so tests run without calling the Flagsmith API: offline mode with LocalFileHandler + a downloaded environment.json snapshot, local-evaluation mode (no per-request network), and default_flag_handler for per-feature mocked fallbacks, via the get_environment_flags / get_identity_flags evaluation paths. Use when writing feature-flag tests for code that uses Flagsmith, mocking flag values, or testing feature toggles offline in CI.

75

Quality

94%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

High

Do not use without reviewing

Overview
Quality
Evals
Security
Files

flagsmith-modes.mdreferences/

Flagsmith test modes, anti-patterns, and limitations

Deeper detail for flagsmith-testing. Offline mode (covered in the skill spine) is the default for tests; the modes below are secondary.

Local-evaluation mode

Polls the Flagsmith API periodically and evaluates flags locally between refreshes (no per-request network, but not zero network):

flagsmith = Flagsmith(
    environment_key="server-key",
    enable_local_evaluation=True,
    environment_refresh_interval_seconds=60,
)

Local mode polls; offline mode does not. For tests, offline is usually preferred.

default_flag_handler - per-flag mock

Programmatic fallback used when the offline environment.json does not have the flag under test yet:

from flagsmith import Flagsmith
from flagsmith.models import DefaultFlag

def default_flag_handler(feature_name: str) -> DefaultFlag:
    if feature_name == "secret_button":
        return DefaultFlag(enabled=False, value='{"colour": "#b8b8b8"}')
    return DefaultFlag(enabled=False, value=None)

flagsmith = Flagsmith(
    environment_key="test-key",
    default_flag_handler=default_flag_handler,
)

Useful when the offline environment.json does not have the flag you are testing yet.

Anti-patterns

Anti-patternWhy it failsFix
Production env_key in testsReal API calls + analytics pollutionoffline_mode + LocalFileHandler
environment.json not committedTest flakes when prod changesCommit; refresh deliberately
Mixing offline_mode + local_evaluation_modeConflicting; one takes precedencePick one
default_flag_handler returns DefaultFlag with no valueTests for value-based flags fail silentlyAlways set value
Skipping flagsmith.get_identity_flags for identity-scoped testsBypasses per-user logicUse identity API
Per-test new Flagsmith clientSlow initSession-scoped fixture

Limitations

  • environment.json is point-in-time. Drift invisible.
  • default_flag_handler only fires for missing flags in local-eval mode. In offline mode it can be used for fallback.
  • No granular per-user override API. Use traits + segments via the environment.json.
  • Doesn't validate Flagsmith's own logic. Platform-side evaluation is separate.

SKILL.md

tile.json