diff options
| author | Carlton Gibson | 2014-06-24 10:30:08 +0200 | 
|---|---|---|
| committer | Carlton Gibson | 2014-06-24 10:30:08 +0200 | 
| commit | d98245ac2234c2377a6243f8314b31fd68c902af (patch) | |
| tree | 5fa88ae09d97a25e20d0dbf254ad028ef4351bca /tests/utils.py | |
| parent | 3f727ce738776838d8420450ce28485954fbb097 (diff) | |
| parent | 2489e38a06f575aa144644eee683bd87f20186ef (diff) | |
| download | django-rest-framework-d98245ac2234c2377a6243f8314b31fd68c902af.tar.bz2 | |
Merge branch '2.4.0' of github.com:tomchristie/django-rest-framework into #1559
Conflicts:
	docs/topics/release-notes.md
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..a8f2eb0b --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,25 @@ +from contextlib import contextmanager +from rest_framework.compat 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) | 
