我正在尝试为我的博客应用程序运行一些简单的测试。我安装了social_django是因为我希望用户能够使用其Facebook,Twitter或Google帐户登录。
使用python manage.py test
运行测试时,出现此错误。
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_fr File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\config.py", line 143, in create
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'django.test.TestCase' isn't a subclass of AppConfig.
PS C:\Semicolon\Software Engineering\Web Development\Back End\Django Projects\christian_blog\christian_blog> ^C
PS C:\Semicolon\Software Engineering\Web Development\Back End\Django Projects\christian_blog\christian_blog> python manage.py test
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'social_django'
这是我的测试代码。我正在使用在“应用”中创建的默认tests.py文件。
from django.test import TestCase
from christian_blog_app.models import Post
from django.utils import timezone
from django.core.urlresolvers import reverse
from christian_blog.settings import social_django, crispy_forms, coverage, social_login
# Create your tests here.
class PostTest(TestCase):
def create_post(self, title="only a test", body="Testing if the created title matches the expected title"):
return Post.objects.create(title=title, body=body, created_at=timezone.now())
def test_post_creation(self):
w = self.create_post()
self.assertTrue(isinstance(w, Post))
self.assertEqual(w.__str__(), w.title)
您认为我做错了什么?我该如何解决?
您应该检查是否在settings.py中将“ social_django”添加到INSTALLED_APPS中。
我不得不再次安装social_django和其他一些应用。它解决了问题。