やりたいこと
Djangoで作成したアプリのPytestを行いたいです。
環境
・Python 3.6.4
・pytest-3.4.0
・Django version 2.0.2
・Pycharm 2018.1
#やったこと
・Edit Configurationsから、Python Tests→py.testを選択
・targetのscript path に、C:/Users/myname/PycharmProjects/projectname/appname/views.pyを設定
・Applyして、OK
・Pytestを実行
# エラーの内容
Testing started at 16:48 ...
C:\Users\myname\Anaconda3\python.exe "C:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\pycharm_jb_pytest_runner.py" --path C:/Users/eitar/PycharmProjects/projectname/appname/views.py
Launching py.test with arguments C:/Users/myname/PycharmProjects/projectname/appname/views.py in C:\Users\myname\PycharmProjects\projectname\appname
============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-3.4.0, py-1.5.2, pluggy-0.6.0
rootdir: C:\Users\myname\PycharmProjects\projectname\appname, inifile:
plugins: cov-2.5.1, hypothesis-3.38.5
views.py:None (views.py)
views.py:11: in <module>
from .forms import (
forms.py:4: in <module>
from .models import (
models.py:4: in <module>
from django.contrib.auth.models import AbstractUser
......\Anaconda3\lib\site-packages\django\contrib\auth\models.py:2: in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
......\Anaconda3\lib\site-packages\django\contrib\auth\base_user.py:47: in <module>
class AbstractBaseUser(models.Model):
......\Anaconda3\lib\site-packages\django\db\models\base.py💯 in new
app_config = apps.get_containing_app_config(module)
......\Anaconda3\lib\site-packages\django\apps\registry.py:244: in get_containing_app_config
self.check_apps_ready()
......\Anaconda3\lib\site-packages\django\apps\registry.py:127: in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
E django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
collected 0 items / 1 errors
=================================== ERRORS ====================================
__________________________ ERROR collecting views.py __________________________
views.py:11: in <module>
from .forms import (
forms.py:4: in <module>
from .models import (
models.py:4: in <module>
from django.contrib.auth.models import AbstractUser
......\Anaconda3\lib\site-packages\django\contrib\auth\models.py:2: in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
......\Anaconda3\lib\site-packages\django\contrib\auth\base_user.py:47: in <module>
class AbstractBaseUser(models.Model):
......\Anaconda3\lib\site-packages\django\db\models\base.py💯 in new
app_config = apps.get_containing_app_config(module)
......\Anaconda3\lib\site-packages\django\apps\registry.py:244: in get_containing_app_config
self.check_apps_ready()
......\Anaconda3\lib\site-packages\django\apps\registry.py:127: in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
E django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.55 seconds ===========================
Process finished with exit code 0
settings.py
python
1# -*- coding: utf-8 -*- 2 3import os 4from django.core.mail import send_mail 5 6BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 7 8SECRET_KEY = 'secret' 9 10DEBUG = True 11 12ALLOWED_HOSTS = ['127.0.0.1', 'test.com'] 13 14EMAIL_HOST = 'localhost' 15EMAIL_PORT = 1025 16 17INSTALLED_APPS = [ 18 'jet', 19 'app.apps.AppConfig', 20 'django.contrib.admin', 21 'django.contrib.auth', 22 'django.contrib.contenttypes', 23 'django.contrib.sessions', 24 'django.contrib.messages', 25 'django.contrib.staticfiles', 26 'django.contrib.sites', 27 'django.contrib.sitemaps', 28 'social.apps.django_app.default', 29 'django_extensions', 30 'social_django', 31 'import_export', 32 'bootstrap_toolkit', 33 'django.contrib.humanize', 34] 35 36SITE_ID = 1 37 38LOCALE_PATHS = [ 39 os.path.join(BASE_DIR, 'locale'), 40] 41 42MIDDLEWARE = [ 43 'django.middleware.security.SecurityMiddleware', 44 'django.contrib.sessions.middleware.SessionMiddleware', 45 'django.middleware.locale.LocaleMiddleware', 46 'django.middleware.common.CommonMiddleware', 47 'django.middleware.csrf.CsrfViewMiddleware', 48 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 'django.contrib.messages.middleware.MessageMiddleware', 50 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51] 52 53if DEBUG: 54 INTERNAL_IPS = ('127.0.0.1',) 55 MIDDLEWARE += ( 56 'debug_toolbar.middleware.DebugToolbarMiddleware', 57 ) 58 59 INSTALLED_APPS += ( 60 'debug_toolbar', 61 ) 62 DEBUG_TOOLBAR_PANELS = [ 63 'debug_toolbar.panels.versions.VersionsPanel', 64 'debug_toolbar.panels.timer.TimerPanel', 65 'debug_toolbar.panels.settings.SettingsPanel', 66 'debug_toolbar.panels.headers.HeadersPanel', 67 'debug_toolbar.panels.request.RequestPanel', 68 'debug_toolbar.panels.sql.SQLPanel', 69 'debug_toolbar.panels.staticfiles.StaticFilesPanel', 70 'debug_toolbar.panels.templates.TemplatesPanel', 71 'debug_toolbar.panels.cache.CachePanel', 72 'debug_toolbar.panels.signals.SignalsPanel', 73 'debug_toolbar.panels.logging.LoggingPanel', 74 'debug_toolbar.panels.redirects.RedirectsPanel', 75 ] 76 77 DEBUG_TOOLBAR_CONFIG = { 78 'INTERCEPT_REDIRECTS': False, 79 } 80 81ROOT_URLCONF = 'project.urls' 82 83TEMPLATES = [ 84 { 85 'BACKEND': 'django.template.backends.django.DjangoTemplates', 86 'DIRS': [], 87 'APP_DIRS': True, 88 'OPTIONS': { 89 'context_processors': [ 90 'django.template.context_processors.debug', 91 'django.template.context_processors.request', 92 'django.contrib.auth.context_processors.auth', 93 'django.contrib.messages.context_processors.messages', 94 'social.apps.django_app.context_processors.backends', 95 'social.apps.django_app.context_processors.login_redirect', 96 'django.template.context_processors.static', 97 ], 98 }, 99 }, 100] 101 102AUTHENTICATION_BACKENDS = ( 103 'social_core.backends.facebook.FacebookOAuth2', 104 'django.contrib.auth.backends.ModelBackend', 105) 106 107LOGIN_REDIRECT_URL = '/' 108AUTH_USER_MODEL = 'app.CustomUser' 109 110WSGI_APPLICATION = 'project.wsgi.application' 111 112DATABASES = { 113 } 114} 115 116LANGUAGE_CODE = 'en-us' 117 118TIME_ZONE = 'Asia/Tokyo' 119 120USE_I18N = True 121 122USE_L10N = True 123 124USE_TZ = False 125 126STATIC_URL = '/static/' 127 128MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 129MEDIA_URL = '/media/' 130 131STATIC_ROOT = os.path.join(BASE_DIR, "/app/static/") 132
どこの設定を直せばよいか、手掛かりが分からず困っております。
お気づきの点があれば、ご教示頂ければ幸いです。
よろしくお願い致します。


回答1件
あなたの回答
tips
プレビュー