Lukas Linhart avatar Lukas Linhart committed 27526d8

Make flushing cache optional (resf #30)

Comments (0)

Files changed (2)

djangosanetesting/noseplugins.py

 
 __all__ = ("CherryPyLiveServerPlugin", "DjangoLiveServerPlugin", "DjangoPlugin", "SeleniumPlugin", "SaneTestSelectionPlugin")
 
-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):
         if hasattr(test_case, '_old_root_urlconf'):
             settings.ROOT_URLCONF = test_case._old_root_urlconf
             clear_url_caches()
-        flush_cache()
+        flush_cache(test_case)
         
 class DjangoTranslationPlugin(Plugin):
     """

testproject/settings.py

 
 CACHE_BACKEND = 'locmem://'
 
+DST_FLUSH_DJANGO_CACHE = True
+
 from config import *
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.