djblets.features.testing¶
Helpers for unit tests working with features.
- FeatureStates¶
A type mapping feature instances or IDs to enabled flags.
New in version 3.3.
- class override_feature_checks(feature_states: Dict[Union[Feature, str], bool])[source]¶
Bases:
TestContextDecoratorOverride multiple features for a test.
Changed in version 6.0: Changed from a pure context manager to a class that can act either as a context manager or a decorator for test methods.
Changed in version 1.0.13:
feature_statesnow accepts aFeatureinstance as a key.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.
- __init__(feature_states: Dict[Union[Feature, str], bool]) None[source]¶
Initialize the override.
- Parameters:
feature_states (
dict) – A dictionary of feature IDs or instances to booleans (representing whether the feature is enabled).
- feature_states: FeatureStates¶
The desired feature states.
- __annotations__ = {'_old_state': 'list[dict[str, object]]', 'feature_states': 'FeatureStates'}¶
- class override_feature_check(feature_id: djblets.features.feature.Feature | str, enabled: bool)[source]¶
Bases:
override_feature_checksOverride 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.
Changed in version 6.0: Changed from a pure context manager to a class that can act either as a context manager or a decorator for test methods.
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.
- __annotations__ = {}¶
- __init__(feature_id: djblets.features.feature.Feature | str, enabled: bool) None[source]¶
Initialize the override.
- Parameters:
feature_id (
strordjblets.features.feature.Feature) – The ID or instance of the feature to override.enabled (
bool) – The enabled state for the feature.