Files
edx-platform/lms/djangoapps/experiments/testutils.py
Régis Behmo 16ce16e85e Deprecate ExperimentWaffleFlag.override method
This is part of a removal of the many override methods of toggle
flag/namespace classes. This allows us to remove imports of test modules
from production code.
2020-11-03 19:25:37 +01:00

18 lines
467 B
Python

from contextlib import contextmanager
from mock import patch
from edx_toggles.toggles.testutils import override_waffle_flag
@contextmanager
def override_experiment_waffle_flag(flag, active=True, bucket=1):
"""
Override both the base waffle flag and the experiment bucket value.
"""
if not active:
bucket = 0
with override_waffle_flag(flag, active):
with patch.object(flag, "get_bucket", return_value=bucket):
yield