david
david

Reputation: 6785

Why am I receiving this error about app name in my django unittest?

When running manage.py test, I receive the following error.

======================================================================
ERROR: Failure: RuntimeError (Model class app.pipeline.models.Product doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/local/lib/python3.5/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/local/lib/python3.5/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/local/lib/python3.5/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/local/lib/python3.5/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/local/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 697, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/usr/src/app/pipeline/tests.py", line 9, in <module>
    from .views import job_details
  File "/usr/src/app/pipeline/views.py", line 37, in <module>
    from .models import (Product, Platform, CdTool,
  File "/usr/src/app/pipeline/models.py", line 9, in <module>
    class Product(models.Model):
  File "/usr/local/lib/python3.5/site-packages/django/db/models/base.py", line 113, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class app.pipeline.models.Product doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

settings.py

INSTALLED_APPS = [
    'pipeline.apps.PipelineConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_nose',
    'bootstrap3',
    'bootstrap_pagination',
    'mobilereports',
    'rest_framework',
    'api'
]

This error only gets thrown when I run tests, but does not in any way affect the performance of the website (this is live in production right now).

This project was inherited, and the project or app name may have been previously changed (not sure if the error might be related to this).

Upvotes: 1

Views: 489

Answers (1)

R. Wenger
R. Wenger

Reputation: 288

The reason for this error message has most likely to do with you having an __init__.py in the same folder as the manage.py. If you remove the __init__.py, the test runner shouldn't complain anymore.

For more info see this comment in the Django bugtracker

Adding this here, as I came by this question as I was looking for an answer to the problem.

Upvotes: 2

Related Questions