Skip to content

Commit

Permalink
Fixed app registry cleanup in app-loading tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jan 5, 2014
1 parent d4b059d commit 5d9da75
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tests/app_loading/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ def setUp(self):
self.old_path = sys.path[:]
self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))

# The models need to be removed after the test in order to prevent bad
# interactions with the flush operation in other tests.
self._old_models = apps.all_models['app_loading'].copy()

def tearDown(self):
apps.all_models['app_loading'] = self._old_models
apps.clear_cache()

sys.path = self.old_path

def test_egg1(self):
Expand All @@ -32,6 +26,7 @@ def test_egg1(self):
with self.settings(INSTALLED_APPS=['app_with_models']):
models_module = apps.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
del apps.all_models['app_with_models']

This comment has been minimized.

Copy link
@apollo13

apollo13 Jan 5, 2014

Member

Can you move this into tearDown?

This comment has been minimized.

Copy link
@aaugustin

aaugustin Jan 5, 2014

Author Member

Not really because the line is different in different tests.

This comment has been minimized.

Copy link
@apollo13

apollo13 Jan 5, 2014

Member

Well you could try deleting both of them in tearDown, currently if a test fails all_models will leak broken data into the env…


def test_egg2(self):
"""Loading an app from an egg that has no models returns no models (and no error)"""
Expand All @@ -40,6 +35,7 @@ def test_egg2(self):
with self.settings(INSTALLED_APPS=['app_no_models']):
models_module = apps.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
del apps.all_models['app_no_models']

def test_egg3(self):
"""Models module can be loaded from an app located under an egg's top-level package"""
Expand All @@ -48,6 +44,7 @@ def test_egg3(self):
with self.settings(INSTALLED_APPS=['omelet.app_with_models']):
models_module = apps.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
del apps.all_models['app_with_models']

def test_egg4(self):
"""Loading an app with no models from under the top-level egg package generates no error"""
Expand All @@ -56,6 +53,7 @@ def test_egg4(self):
with self.settings(INSTALLED_APPS=['omelet.app_no_models']):
models_module = apps.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
del apps.all_models['app_no_models']

def test_egg5(self):
"""Loading an app from an egg that has an import error in its models module raises that error"""
Expand Down

0 comments on commit 5d9da75

Please sign in to comment.