Skip to main content

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

Release files for pytest-openfeature 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-openfeature 0.1.1
File Size Uploaded
pytest_openfeature-0.1.1.tar.gz 19.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-openfeature 0.1.1
File Interpreter ABI Platform
pytest_openfeature-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size:39.0 kB

Release files / pytest_openfeature-0.1.1.tar.gz

Download URL pytest_openfeature-0.1.1.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8e49180e72f2cc59fb780a2863133f4ba1a7e3d4a0525d40e6c92ddbfdf6cee3
BLAKE2b-256 checksum
How to use checksums
b9043986c076d37325cf056da1182c5e2e52c8dfa24bc5ee91353846d9c96aa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.

Transparency log

Release files / pytest_openfeature-0.1.1-py3-none-any.whl

Download URL pytest_openfeature-0.1.1-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
041070697963410259fecf4e0d85ee1673e0634f6c9271a02a458b6cf3dc56e7
BLAKE2b-256 checksum
How to use checksums
d9951edd9bd3a49f6a0c70555d5ebfb1b88f13a29f9ae0d495eb255c11c74219
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page