-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use flags in tests? #121
Comments
@dimaqq Sure! Because An example is in Django-Flags's own tests, where we test flagging URLs: class FlaggedCodeTestCase(TestCase):
@override_settings(FLAGS={"MY_FLAG": [("boolean", True)]})
def test_flag_enabled(self):
# Do the thing that requires the flag to be enabled
@override_settings(FLAGS={"MY_FLAG": [("boolean", False)]})
def test_flag_disabled(self):
# Do the thing that requires the flag to be disabled Here one tests overrides Unless you're overriding If for some reason you've completely disabled the We don't have a direct example of this in Django-Flags's tests (because it's more complex, and is database-dependent), but the class FlaggedCodeTestCase(TestCase):
def test_flag_enabled(self):
FlagState.objects.create(
name="MY_FLAG", condition="boolean", value="True"
)
# Do the thing that requires the flag to be enabled
def test_flag_disabled(self):
FlagState.objects.create(
name="MY_FLAG", condition="boolean", value="True"
)
# Do the thing that requires the flag to be disabled I hope this helps! Generally, there's nothing inherently unique about testing with flags enabled or disabled in Django-Flags, it uses pretty standard Django testing paradigms with either settings or models. |
For example, I'd like to test 2 code paths, with flag on and off.
In my case the flag is only sourced from the database (not url params).
I imagine this is a common question, if there's a good answer already, I volunteer to add it to documentation.
The text was updated successfully, but these errors were encountered: