0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

django アプリケーションテスト時のエラー

Posted at

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を削除したところエラーが解消された。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?