【发布时间】:2020-05-30 20:29:28
【问题描述】:
我正在尝试为我的博客应用程序运行一些简单的测试。我安装了 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 是什么样的?
-
INSTALLED_APPS = ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages' , 'django.contrib.staticfiles', 'christian_blog_app', 'contacts', 'social_django', 'social_login', 'crispy_forms', 'coverage', ] MIDDLEWARE = ['django.middleware.security.SecurityMiddleware', 'django. contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware',
标签: python django django-tests