【发布时间】:2020-07-17 13:35:43
【问题描述】:
我已经部署了一个 Django 应用程序,并希望设置 Heroku CI。我有一套在本地运行的测试。在 heroku CI 测试设置成功,然后测试运行程序失败并显示以下错误日志(缩写):
==================================== ERRORS ====================================
________________________ ERROR collecting test session _________________________
.heroku/python/lib/python3.8/site-packages/_pytest/config/__init__.py:495: in _importconftest
return self._conftestpath2mod[key]
E KeyError: PosixPath('/app/.heroku/python/lib/python3.8/site-packages/django_dynamic_fixture/tests/conftest.py')
During handling of the above exception, another exception occurred:
...
.heroku/python/lib/python3.8/site-packages/django/db/models/base.py:112: in __new__
raise RuntimeError(
E RuntimeError: Model class django_dynamic_fixture.models_sample_app.Publisher doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
如您所见,此错误源于导入的模块 (django_dynamic_fixture),该模块在本地运行良好。我认为这可能是由于 heroku ci 的配置方式,因此我不知道我能做些什么来解决这个问题。
doesn't declare an explicit app_label... 错误可能是由于混合了绝对和相对导入,或者由于 django 设置文件中缺少 django.contrib.sites 应用程序。但是由于测试在本地运行,我不确定如何继续。
【问题讨论】:
-
您是否检查过您的
settings_dev.py和settings_prod.py(假设您分别拥有它们)两者的应用名称都在INSTALLED APPS列表中? -
设置文件和 INSTALLED_APPS 没问题 - 我可以在本地运行测试,指定 settings.test 文件。它似乎是 heroku 平台本身的东西
标签: django pytest cookiecutter-django heroku-ci