<s> import shutil <EOL> import os <EOL> from django_nose . plugin import AlwaysOnPlugin <EOL> from django . test import TestCase <EOL> from django . core . cache import cache <EOL> from django . conf import settings <EOL> class UnitTestDiscoveryPlugin ( AlwaysOnPlugin ) : <EOL> """<STR_LIT>""" <EOL> enabled = True <EOL> def wantModule ( self , module ) : <EOL> return True <EOL> def wantFile ( self , file ) : <EOL> if file . endswith ( '<STR_LIT>' ) : <EOL> return True <EOL> def wantClass ( self , cls ) : <EOL> if not issubclass ( cls , TestCase ) : <EOL> return False <EOL> def wantMethod ( self , method ) : <EOL> if not method . __name__ . lower ( ) . startswith ( '<STR_LIT:test>' ) : <EOL> return False <EOL> def wantFunction ( self , function ) : <EOL> return False <EOL> class PrepareRestFrameworkSettingsPlugin ( AlwaysOnPlugin ) : <EOL> def begin ( self ) : <EOL> self . _monkeypatch_default_settings ( ) <EOL> def _monkeypatch_default_settings ( self ) : <EOL> from rest_framework import settings <EOL> PATCH_REST_FRAMEWORK = { <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> for key , value in PATCH_REST_FRAMEWORK . items ( ) : <EOL> if key not in settings . DEFAULTS : <EOL> settings . DEFAULTS [ key ] = value <EOL> class PrepareFileStorageDir ( AlwaysOnPlugin ) : <EOL> def begin ( self ) : <EOL> if not os . path . isdir ( settings . FILE_STORAGE_DIR ) : <EOL> os . makedirs ( settings . FILE_STORAGE_DIR ) <EOL> def finalize ( self , result ) : <EOL> shutil . rmtree ( settings . FILE_STORAGE_DIR , ignore_errors = True ) <EOL> class FlushCache ( AlwaysOnPlugin ) : <EOL> def begin ( self ) : <EOL> self . _monkeypatch_testcase ( ) <EOL> def _monkeypatch_testcase ( self ) : <EOL> old_run = TestCase . run <EOL> def new_run ( * args , ** kwargs ) : <EOL> cache . clear ( ) <EOL> return old_run ( * args , ** kwargs ) <EOL> TestCase . run = new_run </s>
