やりたいこと
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
# -*- coding: utf-8 -*- import os from django.core.mail import send_mail BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = 'secret' DEBUG = True ALLOWED_HOSTS = ['127.0.0.1', 'test.com'] EMAIL_HOST = 'localhost' EMAIL_PORT = 1025 INSTALLED_APPS = [ 'jet', 'app.apps.AppConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.sitemaps', 'social.apps.django_app.default', 'django_extensions', 'social_django', 'import_export', 'bootstrap_toolkit', 'django.contrib.humanize', ] SITE_ID = 1 LOCALE_PATHS = [ os.path.join(BASE_DIR, 'locale'), ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] if DEBUG: INTERNAL_IPS = ('127.0.0.1',) MIDDLEWARE += ( 'debug_toolbar.middleware.DebugToolbarMiddleware', ) INSTALLED_APPS += ( 'debug_toolbar', ) DEBUG_TOOLBAR_PANELS = [ 'debug_toolbar.panels.versions.VersionsPanel', 'debug_toolbar.panels.timer.TimerPanel', 'debug_toolbar.panels.settings.SettingsPanel', 'debug_toolbar.panels.headers.HeadersPanel', 'debug_toolbar.panels.request.RequestPanel', 'debug_toolbar.panels.sql.SQLPanel', 'debug_toolbar.panels.staticfiles.StaticFilesPanel', 'debug_toolbar.panels.templates.TemplatesPanel', 'debug_toolbar.panels.cache.CachePanel', 'debug_toolbar.panels.signals.SignalsPanel', 'debug_toolbar.panels.logging.LoggingPanel', 'debug_toolbar.panels.redirects.RedirectsPanel', ] DEBUG_TOOLBAR_CONFIG = { 'INTERCEPT_REDIRECTS': False, } ROOT_URLCONF = 'project.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'social.apps.django_app.context_processors.backends', 'social.apps.django_app.context_processors.login_redirect', 'django.template.context_processors.static', ], }, }, ] AUTHENTICATION_BACKENDS = ( 'social_core.backends.facebook.FacebookOAuth2', 'django.contrib.auth.backends.ModelBackend', ) LOGIN_REDIRECT_URL = '/' AUTH_USER_MODEL = 'app.CustomUser' WSGI_APPLICATION = 'project.wsgi.application' DATABASES = { } } LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True USE_TZ = False STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' STATIC_ROOT = os.path.join(BASE_DIR, "/app/static/")
どこの設定を直せばよいか、手掛かりが分からず困っております。
お気づきの点があれば、ご教示頂ければ幸いです。
よろしくお願い致します。
まだ回答がついていません
会員登録して回答してみよう