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-seedfor a day, then roll forward. - Flip
-xon for a subset of branches without editing every workflow. - Roll out a
pytestinvocation 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_openfeature-0.1.0.tar.gz.
File metadata
- Download URL: pytest_openfeature-0.1.0.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cff502832d5a5176dd3626733e418ca7406c57075e847370ccfef5083f10525e
|
|
| MD5 |
6a264d97ffa554290f8d40133b4ef30e
|
|
| BLAKE2b-256 |
a0a38bb53ae77378e8ca75a8b683085a11838393a7c004361c1890a6622fbf63
|
File details
Details for the file pytest_openfeature-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_openfeature-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb3795a05ec639b85617edfb98e52b40e6050b63ef3baf5008094c9b675a04f0
|
|
| MD5 |
57f4c2665591ae0ccc6c2680d064e9a8
|
|
| BLAKE2b-256 |
97fc73c79dc09f736c2372dd0a1c3e9448ee1c19ade8a6cb9333a97a92cca5db
|