Heroku CI with pytest-django fails - module "doesn't declare an explicit app_label"

365 Views Asked by At

I've deployed a Django app and would like to get Heroku CI setup. I have a suite of tests that run locally. On heroku CI test setup succeeds and then the test runner fails with the following error log (abbreviated):

==================================== 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.

As you can see, this error originates in an imported module (django_dynamic_fixture) which runs fine locally. I think this may be due to how heroku ci is configured and therefore I don't know what I can do to solve this issue.

The doesn't declare an explicit app_label... error is probably due to mixing absolute and relative imports, or from a missing django.contrib.sites app in the django settings file. However because the tests run locally, I'm unsure how to proceed.

1

There are 1 best solutions below

0
On

The problem was caused by using the ignore option. Instead of using ignore, use norecursedirs instead.

Also, tests are run from the app/ dir, so any norecursedirs should not include this dir, but only its children. e.g. .heroku, not app/.heroku