Navigation Menu

Skip to content

Commit

Permalink
Making autodiscover more robust. Don't break if some module can't be …
Browse files Browse the repository at this point in the history
…imported.
  • Loading branch information
gregmuellegger committed Aug 24, 2010
1 parent 00b560d commit 939b700
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions autofixture/__init__.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import warnings
from autofixture.base import AutoFixture
from autofixture.constraints import InvalidConstraint

Expand Down Expand Up @@ -151,7 +152,11 @@ def autodiscover():

# Step 3: import the app's autofixtures file. If this has errors we want them
# to bubble up.
import_module("%s.autofixtures" % app)
try:
import_module("%s.autofixtures" % app)
except Exception, e:
warnings.warn(u'Error while importing %s.autofixtures: %r' %
(mod.__name__, e))

for app in settings.INSTALLED_APPS:
mod = import_module(app)
Expand All @@ -165,7 +170,11 @@ def autodiscover():
except ImportError:
continue

import_module("%s.tests" % app)
try:
import_module("%s.tests" % app)
except Exception, e:
warnings.warn(u'Error while importing %s.tests: %r' %
(mod.__name__, e))

# autodiscover was successful, reset loading flag.
LOADING = False
2 changes: 2 additions & 0 deletions autofixture_tests/settings.py
Expand Up @@ -79,6 +79,8 @@
'django.contrib.sites',
'django.contrib.admin',

'django_extensions',

'autofixture_tests.sample_app',
'autofixture_tests.autofixture_test',
'autofixture_tests.generator_test',
Expand Down

0 comments on commit 939b700

Please sign in to comment.