Skip to main content

Drive pytest configuration from an OpenFeature provider.

Project description

pytest-openfeature

Drive pytest configuration from an OpenFeature provider. Resolve registered pytest options (CLI and ini) at session start so a single feature-flag service can steer your test fleet — most obviously, pytest-randomly's --randomly-seed, but any registered option works.

Status: early/draft. The API and configuration surface may change before 1.0.

Why

You have a fleet of CI runs and you'd like to:

  • Pin them all to the same --randomly-seed for a day, then roll forward.
  • Flip -x on for a subset of branches without editing every workflow.
  • Roll out a pytest invocation tweak gradually using your existing flag service's targeting rules.

pytest-openfeature resolves a flag from any spec-compliant OpenFeature provider and writes its value into the matching pytest option before the plugin chain reads it.

Install

pip install pytest-openfeature
# plus any OpenFeature provider you use, e.g.:
pip install openfeature-provider-flagd

Quick start

# pyproject.toml
[tool.pytest_openfeature]
strict = false

[tool.pytest_openfeature.flags]
"ci.pytest_randomly_seed" = "randomly_seed"

[tool.pytest_openfeature.provider]
type = "flagd"
endpoint = "https://flagd.internal/eu"
$ pytest tests/
openfeature: provider=flagd, 1 flag resolved
  randomly_seed       <-- ci.pytest_randomly_seed  = 20260427    (TARGETING_MATCH)
Using --randomly-seed=20260427
================== test session starts ==================

A developer overriding the flag locally still wins:

$ pytest --randomly-seed=42 tests/

CLI > PYTEST_ADDOPTS > OpenFeature > ini > pytest default.

Configuration

key type default meaning
auto_resolve bool true Resolve any flag whose key matches a pytest option name.
strict bool false Fail the run on resolution errors instead of falling back.
domain str "" OpenFeature client domain.
flags table {} Explicit flag_key = pytest_option mapping.
resolve_timeout float 1.0 Per-resolution timeout in seconds.
override_addopts bool false Allow OF to inject CLI tokens before parsing.
addopts_merge str "append" append / prepend / replace.
addopts_flag_key str "pytest.addopts" Flag key for the addopts slot.
provider table none Provider bootstrap (type, plus kwargs).

Equivalent ini keys ([pytest] / [tool:pytest] / setup.cfg) all start with openfeature_. Env vars use PYTEST_OPENFEATURE_*.

Hooks

Plugin authors can register a provider or modify the evaluation context from a project's conftest.py:

def pytest_openfeature_provider(config):
    from my_provider import MyProvider
    return MyProvider(api_key=os.environ["FF_KEY"])

def pytest_openfeature_context(config, context):
    context.attributes["team"] = "platform"
    return context

Fixtures

openfeature_client exposes the session-scoped client to your tests when you want to consult flags from inside a test.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_openfeature-0.1.1.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_openfeature-0.1.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_openfeature-0.1.1.tar.gz.

File metadata

  • Download URL: pytest_openfeature-0.1.1.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_openfeature-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8e49180e72f2cc59fb780a2863133f4ba1a7e3d4a0525d40e6c92ddbfdf6cee3
MD5 cb6a19b553bd1925788b0d8886bcd68c
BLAKE2b-256 b9043986c076d37325cf056da1182c5e2e52c8dfa24bc5ee91353846d9c96aa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_openfeature-0.1.1.tar.gz:

Publisher: release.yml on jirikuncar/pytest-openfeature

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_openfeature-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_openfeature-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 041070697963410259fecf4e0d85ee1673e0634f6c9271a02a458b6cf3dc56e7
MD5 40abfad0c6f49730fa4e8dab05db34cf
BLAKE2b-256 d9951edd9bd3a49f6a0c70555d5ebfb1b88f13a29f9ae0d495eb255c11c74219

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_openfeature-0.1.1-py3-none-any.whl:

Publisher: release.yml on jirikuncar/pytest-openfeature

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page