test.py 560 B

12345678910111213141516171819202122
  1. from functools import wraps
  2. from misago.conf.dynamicsettings import DynamicSettings
  3. class override_dynamic_settings:
  4. def __init__(self, **settings):
  5. self._overrides = settings
  6. def __enter__(self):
  7. DynamicSettings.override_settings(self._overrides)
  8. def __exit__(self, *_):
  9. DynamicSettings.remove_overrides()
  10. def __call__(self, f):
  11. @wraps(f)
  12. def test_function_wrapper(*args, **kwargs):
  13. with self as context:
  14. return f(*args, **kwargs)
  15. return test_function_wrapper