Commits

Lukas Linhart committed 3c82a31 Merge

Merged with upstream

  • Participants
  • Parent commits 924bf08, 27526d8

Comments (0)

Files changed (3)

djangosanetesting/noseplugins.py

 from django.core.management import call_command
 from django.core.handlers.wsgi import WSGIHandler
 from django.core.servers.basehttp import  WSGIRequestHandler, AdminMediaHandler, WSGIServerException
+from django.core.urlresolvers import clear_url_caches
 
 import nose
 from nose.plugins import Plugin
 
 __all__ = ("CherryPyLiveServerPlugin", "DjangoLiveServerPlugin", "DjangoPlugin", "SeleniumPlugin", "SaneTestSelectionPlugin")
 
-def flush_urlconf(case):
-    if hasattr(case, '_old_root_urlconf'):
-        settings.ROOT_URLCONF = case._old_root_urlconf
-        clear_url_caches()
-
-def flush_cache():
+def flush_cache(test_case=None):
     from django.contrib.contenttypes.models import ContentType
     ContentType.objects.clear_cache()
 
-    djangosanetesting.cache.flush_django_cache()
+    from django.conf import settings
 
+    if (test_case and hasattr(test_case, "flush_django_cache") and test_case.flush_django_cache) \
+        or (not hasattr(test_case, "flush_django_cache") and getattr(settings, "DST_FLUSH_DJANGO_CACHE", False)):
+        djangosanetesting.cache.flush_django_cache()
 
 def get_test_case_class(nose_test):
     if isinstance(nose_test.test, nose.case.MethodTestCase):
         After test is run, clear urlconf and caches
         """
         from django.db import transaction
+        from django.conf import settings
         
         test_case = get_test_case_class(test)
         
             transaction.rollback()
             transaction.leave_transaction_management()
 
-        flush_urlconf(self)
-        flush_cache()
+        if hasattr(test_case, '_old_root_urlconf'):
+            settings.ROOT_URLCONF = test_case._old_root_urlconf
+            clear_url_caches()
+        flush_cache(test_case)
         
 class DjangoTranslationPlugin(Plugin):
     """
 Running tests
 ---------------------------
 
-Easiest way to run tests is to put *TEST_RUNNER='djangosanetesting.testrunner.run_tests'* into your :file:`settings.py`. This still allows you to select individual tests by running ``./manage.py test testpackage.module.module:Class.method``, however there is no way to disable some tests (by not using some plugin) or to use additional nose plugins.
+Easiest way to run tests is to put ``TEST_RUNNER="djangosanetesting.testrunner.run_tests"`` into your :file:`settings.py`. This still allows you to select individual tests by running ``./manage.py test testpackage.module.module:Class.method``, however there is no way to disable some tests (by not using some plugin) or to use additional nose plugins.
 
 More flexible and granular way is using standard ``nosetests`` command. However, keep in mind:
 

testproject/settings.py

 
 CACHE_BACKEND = 'locmem://'
 
+DST_FLUSH_DJANGO_CACHE = True
 NONSENSICAL_SETTING_ATTRIBUTE_FOR_MOCK_TESTING = "owned"
 
 from config import *