Test Utilities

class gargoyle.testutils.SwitchContextManager(gargoyle=<SimpleLazyObject: <SwitchManager: <class 'gargoyle.models.Switch'> (dict_values([]))>>, **keys)

Allows temporarily enabling or disabling a switch.

Ideal for testing.

>>> @switches(my_switch_name=True)
>>> def foo():
>>>     print(gargoyle.is_active('my_switch_name'))
>>> def foo():
>>>     with switches(my_switch_name=True):
>>>         print(gargoyle.is_active('my_switch_name'))

You may also optionally pass an instance of SwitchManager as the first argument.

>>> def foo():
>>>     with switches(gargoyle, my_switch_name=True):
>>>         print(gargoyle.is_active('my_switch_name'))

Can also wrap unittest classes, which includes Django’s TestCase classes:

>>> @switches(my_switch_name=True)
... class MyTests(TestCase):
...     @classmethod
...     def setUpTestData(cls):
...         # my_switch_name is True here
...
...     def test_foo(self):
...          # ... and here