Skip to content

Commit 99b6571

Browse files
committed
Add docs/feature-flags.md
* Documentation for the yml openfeature implementation
1 parent 2a17f64 commit 99b6571

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

docs/feature-flags.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Feature flags
2+
3+
Feature flags are implemented using [OpenFeature](https://openfeature.dev/) with an `InMemoryProvider`. Flags are declared in YAML files and loaded at startup.
4+
5+
## Flag files
6+
7+
Each environment has its own flag file. The application selects the file based on the `DEPLOYED_TO` environment variable, falling back to `flags.yml` for local development where `DEPLOYED_TO` is not set.
8+
9+
| Environment | File |
10+
| ---------------------------- | ---------------------- |
11+
| dev | `flags.dev.yml` |
12+
| review | `flags.review.yml` |
13+
| preprod | `flags.preprod.yml` |
14+
| production | `flags.production.yml` |
15+
| local (no `DEPLOYED_TO` set) | `flags.yml` |
16+
17+
## Adding a flag
18+
19+
**1. Declare the flag in each environment's file.**
20+
21+
Add an entry to all five flag files (`flags.yml`, `flags.dev.yml`, `flags.review.yml`, `flags.preprod.yml`, `flags.production.yml`). Set the value to `true` to enable or `false` to disable in that environment.
22+
23+
```yaml
24+
flags:
25+
my_flag: false
26+
```
27+
28+
**2. Check the flag in application code.**
29+
30+
```python
31+
from manage_breast_screening.core.feature_flags import FeatureFlag
32+
33+
if FeatureFlag.is_enabled("my_flag"):
34+
# feature is enabled
35+
```
36+
37+
`FeatureFlag.is_enabled` returns `False` if the flag is missing or the provider is unavailable. If a flag name is not found in the YAML file, OpenFeature silently returns the fallback rather than raising an error — so a typo in a flag name will return `False` without any indication something is wrong.
38+
39+
## Enabling a flag in tests
40+
41+
Use the `with_flag_enabled` fixture to turn a flag on for the duration of a single test:
42+
43+
```python
44+
def test_something(with_flag_enabled):
45+
with_flag_enabled("my_flag")
46+
# flag is enabled for this test only
47+
```
48+
49+
Multiple flags can be enabled by calling it more than once:
50+
51+
```python
52+
def test_something(with_flag_enabled):
53+
with_flag_enabled("my_flag")
54+
with_flag_enabled("another_flag")
55+
```
56+
57+
In class-based tests the fixture must be relayed via an `autouse` fixture so it is accessible to helper methods:
58+
59+
```python
60+
@pytest.fixture(autouse=True)
61+
def flags(self, with_flag_enabled):
62+
self.with_flag_enabled = with_flag_enabled
63+
64+
def and_my_flag_is_enabled(self):
65+
self.with_flag_enabled("my_flag")
66+
```
67+
68+
After each test the flags are reset to the defaults from the YAML file.

0 commit comments

Comments
 (0)