summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-24 10:08:04 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-24 10:56:50 +0100
commit82a35e24d4de58e637661591b14d9b4658bcab11 (patch)
treee0dabcce9d37651b59f478907778bda547f9cf76 /tests
parent2ec8e3443bc9345d986710244e05a3cce56c8da1 (diff)
Replaced ad-hoc caching of get_models with lru_cache.
Invalidate properly the cache whenever all_models or app_configs change. This fixes some isolation issues in the test suite.
Diffstat (limited to 'tests')
-rw-r--r--tests/app_loading/tests.py2
-rw-r--r--tests/managers_regress/tests.py6
-rw-r--r--tests/migrations/test_commands.py2
-rw-r--r--tests/proxy_models/tests.py2
-rwxr-xr-xtests/runtests.py1
-rw-r--r--tests/swappable_models/tests.py10
-rw-r--r--tests/tablespaces/tests.py2
7 files changed, 8 insertions, 17 deletions
diff --git a/tests/app_loading/tests.py b/tests/app_loading/tests.py
index a9dc70f4b1..291877108f 100644
--- a/tests/app_loading/tests.py
+++ b/tests/app_loading/tests.py
@@ -21,7 +21,7 @@ class EggLoadingTest(TestCase):
def tearDown(self):
app_cache.all_models['app_loading'] = self._old_models
- app_cache._get_models_cache = {}
+ app_cache.get_models.cache_clear()
sys.path = self.old_path
diff --git a/tests/managers_regress/tests.py b/tests/managers_regress/tests.py
index 2b8e183e82..bf8e5b17d4 100644
--- a/tests/managers_regress/tests.py
+++ b/tests/managers_regress/tests.py
@@ -128,7 +128,7 @@ class ManagersRegressionTests(TestCase):
finally:
app_cache.app_configs['managers_regress'].models = _old_models
app_cache.all_models['managers_regress'] = _old_models
- app_cache._get_models_cache = {}
+ app_cache.get_models.cache_clear()
@override_settings(TEST_SWAPPABLE_MODEL='managers_regress.Parent')
def test_custom_swappable_manager(self):
@@ -156,7 +156,7 @@ class ManagersRegressionTests(TestCase):
finally:
app_cache.app_configs['managers_regress'].models = _old_models
app_cache.all_models['managers_regress'] = _old_models
- app_cache._get_models_cache = {}
+ app_cache.get_models.cache_clear()
@override_settings(TEST_SWAPPABLE_MODEL='managers_regress.Parent')
def test_explicit_swappable_manager(self):
@@ -184,7 +184,7 @@ class ManagersRegressionTests(TestCase):
finally:
app_cache.app_configs['managers_regress'].models = _old_models
app_cache.all_models['managers_regress'] = _old_models
- app_cache._get_models_cache = {}
+ app_cache.get_models.cache_clear()
def test_regress_3871(self):
related = RelatedModel.objects.create()
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 9f740f72a2..9fa9be6cbf 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -136,7 +136,7 @@ class MakeMigrationsTests(MigrationTestBase):
def tearDown(self):
app_cache.app_configs['migrations'].models = self._old_models
app_cache.all_models['migrations'] = self._old_models
- app_cache._get_models_cache = {}
+ app_cache.get_models.cache_clear()
os.chdir(self.test_dir)
try:
diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
index 346924e320..4a3d6e5e5a 100644
--- a/tests/proxy_models/tests.py
+++ b/tests/proxy_models/tests.py
@@ -175,7 +175,7 @@ class ProxyModelTests(TestCase):
finally:
app_cache.app_configs['proxy_models'].models = _old_models
app_cache.all_models['proxy_models'] = _old_models
- app_cache._get_models_cache = {}
+ app_cache.get_models.cache_clear()
def test_myperson_manager(self):
Person.objects.create(name="fred")
diff --git a/tests/runtests.py b/tests/runtests.py
index c75d8a3ee9..ab6f778a81 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -170,6 +170,7 @@ def setup(verbosity, test_labels):
app_config = AppConfig.create(module_label)
app_config.import_models(app_cache.all_models[app_config.label])
app_cache.app_configs[app_config.label] = app_config
+ app_cache.get_models.cache_clear()
return state
diff --git a/tests/swappable_models/tests.py b/tests/swappable_models/tests.py
index cdebbef374..c703a99fcb 100644
--- a/tests/swappable_models/tests.py
+++ b/tests/swappable_models/tests.py
@@ -19,16 +19,6 @@ class SwappableModelTests(TestCase):
'django.contrib.contenttypes',
]
- def setUp(self):
- # This test modifies the installed apps, so we need to make sure
- # we're not dealing with a cached app list.
- app_cache._get_models_cache.clear()
-
- def tearDown(self):
- # By fiddling with swappable models, we alter the installed models
- # cache, so flush it to make sure there are no side effects.
- app_cache._get_models_cache.clear()
-
@override_settings(TEST_ARTICLE_MODEL='swappable_models.AlternateArticle')
def test_generated_data(self):
"Permissions and content types are not created for a swapped model"
diff --git a/tests/tablespaces/tests.py b/tests/tablespaces/tests.py
index d761a93ab9..fdee877a9f 100644
--- a/tests/tablespaces/tests.py
+++ b/tests/tablespaces/tests.py
@@ -37,7 +37,7 @@ class TablespacesTests(TestCase):
app_cache.app_configs['tablespaces'].models = self._old_models
app_cache.all_models['tablespaces'] = self._old_models
- app_cache._get_models_cache = {}
+ app_cache.get_models.cache_clear()
def assertNumContains(self, haystack, needle, count):
real_count = haystack.count(needle)