Mezzanine ImportError when running tests
我最近将Django的版本从1.5.5升级到1.6.2,将Mezzanine升级到3.0.9。
我跑的时候
1 | python manage.py test |
所有测试都没有问题。
但是当我使用时运行项目特定的测试
1 | python manage.py test <project-name> |
然后我得到ImportError。 我认为它与Circular Imports有关。
这是堆栈跟踪。 请帮忙。
======================================================================
ERROR: Failure: ImportError (cannot import name DisplayableAdmin)
---------------------------------------------------------------------- Traceback (most recent call last): File
"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/nose/loader.py",
line 411, in loadTestsFromName
addr.filename, addr.module) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/nose/importer.py",
line 47, in importFromPath
return self.importFromDir(dir_path, fqname) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/nose/importer.py",
line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc) File"/Users/devarajn/repos/pari/pari/album/tests.py", line 8, in
from pari.album.admin import AlbumAdmin, AlbumImageInline File"/Users/devarajn/repos/pari/pari/album/admin.py", line 2, in
from mezzanine.core.admin import TabularDynamicInlineAdmin File
"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/mezzanine/core/admin.py",
line 4, in
from django.contrib.auth.admin import UserAdmin File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/contrib/auth/admin.py", line 182, in
admin.site.register(Group, GroupAdmin) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/mezzanine/boot/lazy_admin.py", line 26, in register
super(LazyAdminSite, self).register(*args, **kwargs) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 92, in register
admin_class.validate(model) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/contrib/admin/options.py", line 105, in validate
validator = cls.validator_class() File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/contrib/admin/validation.py",
line 20, in init
models.get_apps() File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/db/models/loading.py",
line 139, in get_apps
self._populate() File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/db/models/loading.py",
line 78, in _populate
self.load_app(app_name) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/db/models/loading.py",
line 99, in load_app
models = import_module('%s.models' % app_name) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/utils/importlib.py",
line 40, in import_module
import(name) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/debug_toolbar/models.py",
line 63, in
patch_root_urlconf() File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/debug_toolbar/models.py",
line 51, in patch_root_urlconf
reverse('djdt:render_panel') File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 480, in reverse
app_list = resolver.app_dict[ns] File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 310, in app_dict
self._populate() File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 262, in _populate
for pattern in reversed(self.url_patterns): File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 346, in url_patterns
patterns = getattr(self.urlconf_module,"urlpatterns", self.urlconf_module) File
"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 341, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/utils/importlib.py",
line 40, in import_module
import(name) File"/Users/devarajn/repos/pari/pari/urls.py", line 7, in
admin.autodiscover() File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/mezzanine/boot/init.py",
line 77, in autodiscover
django_autodiscover(*args, **kwargs) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/contrib/admin/init.py",
line 29, in autodiscover
import_module('%s.admin' % app) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/django/utils/importlib.py",
line 40, in import_module
import(name) File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/mezzanine/forms/admin.py",
line 24, in
from mezzanine.pages.admin import PageAdmin File"/Users/devarajn/.pythonbrew/venvs/Python-2.7.3/pari/lib/python2.7/site-packages/mezzanine/pages/admin.py",
line 12, in
from mezzanine.core.admin import DisplayableAdmin, DisplayableAdminForm ImportError: cannot import name
DisplayableAdminBLOCKQUOTE>
django-debug-toolbar模块导致了这个问题。
我从django-debug-toolbar v1.0.1回滚到v0.11。
这修复了错误。