Metadata-Version: 2.4
Name: pytest-openfeature
Version: 0.1.1
Summary: Drive pytest configuration from an OpenFeature provider.
Keywords: pytest,openfeature,feature-flags,configuration
Author: Jiri Kuncar
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Testing :: Acceptance
Classifier: Typing :: Typed
Requires-Dist: pytest>=8.0
Requires-Dist: openfeature-sdk>=0.7
Requires-Dist: pytest-xdist>=3.0 ; extra == 'xdist'
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/jirikuncar/pytest-openfeature
Project-URL: Issues, https://github.com/jirikuncar/pytest-openfeature/issues
Project-URL: Source, https://github.com/jirikuncar/pytest-openfeature
Provides-Extra: xdist
Description-Content-Type: text/markdown

# pytest-openfeature

Drive pytest configuration from an [OpenFeature](https://openfeature.dev)
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

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

## Quick start

```toml
# 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`:

```python
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
