Flagsmith / Flagsmith/flagsmith-python-client

Implement a pytest plugin to help with testing

Offen
#135 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
24
Forks
12
Ø Merge
15 Std. 43 Min.
Gemergte PRs (30 T.)
4

Beschreibung

As part of some work in the core Flagsmith repository, we found that there isn't currently a good, generic solution for mocking the flagsmith client to return a given value for a flag at a given time. The ideal implementation as I see it would be to build a fixture that can be used as a context manager, or a function that looks something like this:

```python
def my_test_function(set_flags: FlagsmithSetFlagsFixture) -> None:
with override_flagsmith(flags=[Flag(name="foo", enabled=True, value="foobar")]):
# in here, any calls to Flags.is_feature_enabled,Flags.get_flag and Flags.get_feature_value
# for the feature "foo" will return the values provided as an argument to override_flagsmith
...

def my_other_test_function(set_flags: FlagsmithSetFlagsFixture) -> None:
set_flags(flags=[Flag(name="foo", enabled=True, value="foobar")])

# For the remainder of this test, any calls to Flags.is_feature_enabled,Flags.get_flag
# and Flags.get_feature_value for the feature "foo" will return the values provided as
# an argument to override_flagsmith
```

See PR [here](https://github.com/Flagsmith/flagsmith/pull/5108) for more context / discussions

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.