django アプリケーションテスト時のエラー
ImportError
ターミナル
$ python manage.py test
上記を実行時に
ImportError: 'tests' module incorrectly imported from
のエラーが発生。
原因
同じディレクトリ内に「tests」
と「tests.py」
の両方が存在している事が原因。
diary
├── tests
│ └── test_views.py
└── tests.py
対処法
既存のtests.py
を削除することで解決。
「tests.py」についてはターミナルでstartupコマンドを実行した際に、自動的に作られてしまうので手動で削除する必要がある。
RuntimeError
上記エラー解消後に発生。
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'diary.apps.DiaryConfig',
'accounts.apps.AccountsConfig',
'allauth',
'allauth.account',
]
settingsにはエラーに書かれているdjango.contrib.contenttypes
は書かれているので別のものが原因と思われる。
原因&対処法
このページのコメント欄に書かれている同じディレクトリ内の__init__.py
を削除したところエラーが解消された。
Author And Source
この問題について(django アプリケーションテスト時のエラー), 我々は、より多くの情報をここで見つけました https://qiita.com/pi0329/items/3a1043c8ed2e63ebc7d9著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .