diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2013-10-22 20:38:11 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2013-10-22 22:40:01 -0300 |
| commit | bcc65c13a086f3e6d24dc7fc92a167fd836af501 (patch) | |
| tree | 55d025e8a1e8b7229fafb0fbbd5221db1de699af /django/test/utils.py | |
| parent | 2e74d6cb53a38c4cc08d4a069157be335a486ddd (diff) | |
[1.6.x] Fixed #21307 -- Moved TransRealMixin to django.test.utils.
51d2e1fb23 from master.
Diffstat (limited to 'django/test/utils.py')
| -rw-r--r-- | django/test/utils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/django/test/utils.py b/django/test/utils.py index 535a70b4f7..818ccafdf3 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -2,6 +2,7 @@ from contextlib import contextmanager import logging import re import sys +from threading import local import time import warnings from functools import wraps @@ -441,6 +442,23 @@ def patch_logger(logger_name, log_level): setattr(logger, log_level, orig) +class TransRealMixin(object): + """This is the only way to reset the translation machinery. Otherwise + the test suite occasionally fails because of global state pollution + between tests.""" + def flush_caches(self): + from django.utils.translation import trans_real + trans_real._translations = {} + trans_real._active = local() + trans_real._default = None + trans_real._accepted = {} + trans_real._checked_languages = {} + + def tearDown(self): + self.flush_caches() + super(TransRealMixin, self).tearDown() + + # On OSes that don't provide tzset (Windows), we can't set the timezone # in which the program runs. As a consequence, we must skip tests that # don't enforce a specific timezone (with timezone.override or equivalent), |
