【问题标题】:Heroku CI with pytest-django fails - module "doesn't declare an explicit app_label"带有 pytest-django 的 Heroku CI 失败 - 模块“没有声明显式的 app_label”
【发布时间】: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.pysettings_prod.py(假设您分别拥有它们)两者的应用名称都在INSTALLED APPS 列表中?
  • 设置文件和 INSTALLED_APPS 没问题 - 我可以在本地运行测试,指定 settings.test 文件。它似乎是 heroku 平台本身的东西

标签: django pytest cookiecutter-django heroku-ci


【解决方案1】:

问题是由使用ignore 选项引起的。 不要使用ignore,而是使用norecursedirs

此外,测试是从app/ 目录运行的,因此任何norecursedirs 都不应包含此目录,而应仅包含其子目录。例如.heroku,不是app/.heroku

【讨论】:

    猜你喜欢
    • 2017-03-05
    • 2017-08-06
    • 2018-10-19
    • 2020-06-17
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 2017-11-09
    相关资源
    最近更新 更多