diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index c344686..9bdbe50 100644
|
a
|
b
|
class AppCache(object):
|
| 81 | 81 | Loads the app with the provided fully qualified name, and returns the |
| 82 | 82 | model module. |
| 83 | 83 | """ |
| | 84 | app_module = import_module(app_name) |
| 84 | 85 | self.handled[app_name] = None |
| 85 | 86 | self.nesting_level += 1 |
| 86 | | app_module = import_module(app_name) |
| 87 | 87 | try: |
| 88 | 88 | models = import_module('.models', app_name) |
| 89 | 89 | except ImportError: |
diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
index 5173338..6702822 100644
|
a
|
b
|
import sys
|
| 6 | 6 | import time |
| 7 | 7 | |
| 8 | 8 | from django.conf import Settings |
| 9 | | from django.db.models.loading import cache, load_app, get_model, get_models |
| | 9 | from django.db.models.loading import cache, load_app, get_model, get_models, AppCache |
| | 10 | from django.test.utils import override_settings |
| 10 | 11 | from django.utils.unittest import TestCase |
| 11 | 12 | |
| 12 | 13 | class EggLoadingTest(TestCase): |
| … |
… |
class EggLoadingTest(TestCase):
|
| 59 | 60 | egg_name = '%s/brokenapp.egg' % self.egg_dir |
| 60 | 61 | sys.path.append(egg_name) |
| 61 | 62 | self.assertRaises(ImportError, load_app, 'broken_app') |
| | 63 | raised = None |
| 62 | 64 | try: |
| 63 | 65 | load_app('broken_app') |
| 64 | 66 | except ImportError, e: |
| 65 | | # Make sure the message is indicating the actual |
| 66 | | # problem in the broken app. |
| 67 | | self.assertTrue("modelz" in e.args[0]) |
| | 67 | raised = e |
| | 68 | # Make sure the message is indicating the actual |
| | 69 | # problem in the broken app. |
| | 70 | self.assertTrue(raised is not None) |
| | 71 | self.assertTrue("modelz" in raised.args[0]) |
| | 72 | |
| | 73 | def test_missing_app(self): |
| | 74 | """ |
| | 75 | Test that repeated app loading doesn't succeed in case there is an |
| | 76 | error. Refs #17667. |
| | 77 | """ |
| | 78 | try: |
| | 79 | # AppCache is a Borg, so we can instantiate one and change its loaded to False |
| | 80 | # to force the following code to actually try to populate the cache. |
| | 81 | a = AppCache() |
| | 82 | a.loaded = False |
| | 83 | with override_settings(INSTALLED_APPS=('notexists',)): |
| | 84 | self.assertRaises(ImportError, get_model, 'notexists', 'nomodel', seed_cache=True) |
| | 85 | self.assertRaises(ImportError, get_model, 'notexists', 'nomodel', seed_cache=True) |
| | 86 | finally: |
| | 87 | a.loaded = True |
| 68 | 88 | |
| 69 | 89 | |
| 70 | 90 | class GetModelsTest(TestCase): |