Jump to >

This documentation covers the in-development release of Djblets. You can see the latest stable docs or all previous versions.

djblets.features.testing

Helpers for unit tests working with features.

override_feature_checks(*args, **kwds)[source]

Override multiple features for a test.

Unit tests can make use of this context manager to ensure that one or more features have particular enabled/disabled states before executing any code dependent on those features.

Only the provided features will be modified, with all other feature logic falling back to the default behavior for the configured feature checker.

Version Change:
1.0.13: feature_states now accepts a Feature instance as a key.
Parameters:feature_states (dict) – A dictionary of feature IDs or instances to booleans (representing whether the feature is enabled).

Example

from myproject.features import my_feature_3

feature_states = {
    'my-feature-1': True,
    'my-feature-2': False,
    my_feature_3: True,
}

with override_feature_checks(feature_states):
    # Your test code here.
override_feature_check(*args, **kwds)[source]

Override a feature for a test.

Unit tests can make use of this context manager to ensure that a specific feature has a particular enabled/disabled state before executing any code dependent on that feature.

Only the provided feature will be modified, with all other feature logic falling back to the default behavior for the configured feature checker.

Parameters:

Example

from myproject.features import my_feature_2

with override_feature_check('my-feature', enabled=False):
    # Your test code here.

with override_feature_check(my_feature_2, enabled=True):
    # Your test code here.