Answer the question
In order to leave comments, you need to log in
Error running automated test in Django?
Here is my test:
import datetime
from django.test import TestCase
from django.utils import timezone
from .models import Question
class QuestionModelTests(TestCase):
#tests.py
def test_was_published_recently_with_future_question(self):
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
self.assertIs(future_question.was_published_recently(), False)
Found 1 test(s).
System check identified no issues (0 silenced).
E
======================================================================
ERROR: DJANGO_tutorial.mysite.polls.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: DJANGO_tutorial.mysite.polls.tests
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\unittest\loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\unittest\loader.py", line 377, in _get_module_from_name
__import__(name)
File "D:\PYCHARM_PROJECTS\DJANGO_tutorial\mysite\polls\tests.py", line 4, in <module>
from .models import Question
File "D:\PYCHARM_PROJECTS\DJANGO_tutorial\mysite\polls\models.py", line 9, in <module>
class Question(models.Model):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\base.py", line 132, in __new__
raise RuntimeError(
RuntimeError: Model class DJANGO_tutorial.mysite.polls.models.Question doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
from django.db import models
from django.utils import timezone
import datetime
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
Answer the question
In order to leave comments, you need to log in
An error in the declaration of the application, which is what the error says. Check installed_apps. Perhaps they did not enter the application, perhaps they lost a comma or something else.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question