-
Notifications
You must be signed in to change notification settings - Fork 16
Feature Toggles
New features that are not yet ready for release should be guarded by a feature toggle.
Feature toggles are defined in the _featuretoggles.py submodule.
XY_DATA = FeatureToggle("XY_DATA", CodeReadiness.RELEASE)
NEW_SESSION_API = FeatureToggle("NEW_SESSION_API", CodeReadiness.INCOMPLETE)
You can use the requires_feature
decorator to indicate that a function requires the specified feature toggle. This wraps the function with a feature toggle check which will throw FeatureNotSupportedError
if the feature is not enabled.
@requires_feature(NEW_SESSION_API)
def do_session_stuff(...): ...
To determine whether a feature is enabled by default, the feature toggle code compares the feature's "code readiness" against the global "code readiness level" for the process. By default, the code readiness level is RELEASE
, so only features with a code readiness of RELEASE
are enabled by default.
You can change the code readiness level by setting environment variables:
-
MEASUREMENTLINK_ALLOW_NEXT_RELEASE=1
: allow features with code readiness ofNEXT_RELEASE
orRELEASE
-
MEASUREMENTLINK_ALLOW_INCOMPLETE=1
: allow features with code readiness ofINCOMPLETE
,NEXT_RELEASE
, orRELEASE
You can set these environment variables in the OS environment or in a .env
file. See .env.sample for a sample configuration file that you can use as a starting point.
Regardless of the code readiness level, you can enable specific features by setting environment variables:
-
MEASUREMENTLINK_ENABLE_NEW_SESSION_API=1
: enable theNEW_SESSION_API
feature
In automated tests, the default code readiness level is PROTOTYPE
. Note that this applies only to the pytest
process, not child processes.
You can use marks to enable or disable specific features for a specific test function or test module:
-
@pytest.mark.enable_feature_toggle(NEW_SESSION_API)
: enable theNEW_SESSION_API
feature -
@pytest.mark.disable_feature_toggle(XY_DATA)
: disable theXY_DATA
feature
You can also use marks to set the code readiness level for a specific test function or test module:
-
@pytest.mark.use_code_readiness(CodeReadiness.NEXT_RELEASE)
: allow features with code readiness ofNEXT_RELEASE
orRELEASE