cfpb / django-flags

Feature flags for Django projects
https://cfpb.github.io/django-flags/
Creative Commons Zero v1.0 Universal
260 stars 32 forks source link

Wanted: context manager to temporarily override a flag #84

Open chosak opened 3 years ago

chosak commented 3 years ago

It would be useful to be able to write code like this:

with override_flag(MY_FLAG=True):
    # do some code that checks the value of MY_FLAG

The tests tend to use Django override_settings for this purpose, but this feels too heavy for inline code that only needs to patch a single flag instead of modifying the entire settings structure (not to mention adding a dependency on "test" code).

I realize this might be complicated because of the way that flag states get cached on the request object, but I suspect that using override_settings wouldn't work there either if the flag states were already cached.

willbarton commented 3 years ago

That's a really good idea!