diff options
| author | Tom Christie | 2014-08-20 12:06:29 +0100 |
|---|---|---|
| committer | Tom Christie | 2014-08-20 12:06:29 +0100 |
| commit | 6ffc97c808f8026c063011e2d048604f3a6b70fa (patch) | |
| tree | 93586ece6e50ab5ef6282ffd104e886ed48d9180 /tests/utils.py | |
| parent | f7b3e1e62b8e2c8bd1d1eb79a1cb0b3f4a0559a9 (diff) | |
| parent | 874d2be83c612fb5e04aa6a28901c2afe4bf9d3b (diff) | |
| download | django-rest-framework-6ffc97c808f8026c063011e2d048604f3a6b70fa.tar.bz2 | |
Merge pull request #1770 from tomchristie/2.4.0
2.4.0 Release.
Diffstat (limited to 'tests/utils.py')
| -rw-r--r-- | tests/utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 00000000..28be81bd --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,25 @@ +from contextlib import contextmanager +from django.utils import six +from rest_framework.settings import api_settings + + +@contextmanager +def temporary_setting(setting, value, module=None): + """ + Temporarily change value of setting for test. + + Optionally reload given module, useful when module uses value of setting on + import. + """ + original_value = getattr(api_settings, setting) + setattr(api_settings, setting, value) + + if module is not None: + six.moves.reload_module(module) + + yield + + setattr(api_settings, setting, original_value) + + if module is not None: + six.moves.reload_module(module) |
