0

I am writing an app in Django and I'm trying to do some unit testing but I can't seem to find why the test is failing that is the test page:

import re
from django.test import TestCase
from django.urls import reverse
from . import models



class BasicTests(TestCase):

    def test_firstname(self):
        print('test11')
        acc = models.Accounts()
        acc.first_name = 'Moran'
        self.assertTrue(len(acc.id) <= 9, 'Check name is less than 50 digits long')
        self.assertFalse(len(acc.id) > 50, 'Check name is less than 50 digits long')

the error i get is :

RuntimeError: Model class DoggieSitter.accounts.models.Accounts doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

thats my installed app:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts'
]
ShTurj
  • 1
  • Looks like the installed app should be `DoggieSitter.accounts` based on the error. How are you running the test and where from? – Iain Shelvington Apr 24 '22 at 10:49
  • I am running the command "python manage.py test" from the terminal – ShTurj Apr 24 '22 at 11:15
  • Have you tried adding `DoggieSitter.accounts` to your INSTALLED_APPS setting instead of `accounts`? – Iain Shelvington Apr 24 '22 at 11:23
  • Yes I did but there was an erro"ModuleNotFoundError: No module named 'DoggieSitter'" Moreover I was unable to upload the site add more issues unrelated to the testing – ShTurj Apr 24 '22 at 11:27
  • Hello @ShTurj try to add full app location eg. ***(accounts.apps.AccountsConfig)*** inside your INSTALLED_APPS – Ankit Tiwari Apr 24 '22 at 11:37
  • I am a bit new to the Django framework To add to the installed app Doggiesitter.accounts.Accountsconfig Where the Accounts is the class name? – ShTurj Apr 24 '22 at 11:44
  • Does this answer your question? [Django model "doesn't declare an explicit app\_label"](https://stackoverflow.com/questions/40206569/django-model-doesnt-declare-an-explicit-app-label) – Hamidreza Khorammfar Apr 24 '22 at 12:35
  • i tried and it didn't work to for me – ShTurj Apr 24 '22 at 15:41

0 Answers0