def _reset_django(settings): """ Hackish way to reset the django instance settings and AppConfig :param settings: django settings module """ if settings._wrapped != empty: clear_url_caches() if DJANGO_1_5: from django.db.models.loading import cache as apps apps.app_store = SortedDict() apps.loaded = False apps.handled = {} apps.postponed = [] apps.nesting_level = 0 apps._get_models_cache = {} elif DJANGO_1_6: from django.db.models.loading import cache as apps apps.app_store = SortedDict() apps.loaded = False apps.handled = set() apps.postponed = [] apps.nesting_level = 0 apps._get_models_cache = {} else: from django.apps import apps apps.clear_cache() settings._wrapped = empty clear_url_caches()
def tearDown(self): super(TestModelsLoaderMixin, self).tearDown() call_command('flush', verbosity=0, interactive=False) settings.INSTALLED_APPS = self._models_loader_old_settings # If we added a fake 'models' module to sys.modules, remove it. models_mod = self._tests_loader_models_mod if models_mod: try: del sys.modules[models_mod.__name__] except KeyError: pass if apps: apps.unset_installed_apps() cache.clear_cache() else: if models_mod: del cache.app_store[models_mod] cache._get_models_cache.clear()