ValueError: No module named 'notmigrations' during unit tests
ValueError: No module named 'notmigrations' during unit tests
我有带 django-tenant 插件的 django 应用程序 2.1.7(在数据库中为 saas 创建模式)。
我的问题是单元测试。我 运行 命令:
python manage.py test --settings=project.settings_test
我收到一个错误:ImportError: No module named 'notmigrations'
我的代码在 settings_test 文件中
from .settings_base import *
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return 'notmigrations'
MIGRATION_MODULES = DisableMigrations()
您正在使用一个古老的 hack,用于真正旧版本的 Django (< 1.9),在测试中支持禁用迁移之前。由于您现在使用的是相对较新版本的 Django (2.1.7),因此请从您的测试设置模块中删除该代码。
如果您想在测试中禁用迁移,请使用 the modern approach, which is putting the value to None
in MIGRATION_MODULES
setting。
When you supply None
as a value for an app, Django will consider the app as an app without migrations regardless of an existing migrations submodule. This can be used, for example, in a test settings file to skip migrations while testing (tables will still be created for the apps’ models).
# test_settings.py
from settings import *
MIGRATION_MODULES = {
'auth': None,
'contenttypes': None,
'sessions': None,
...
'myapp1': None,
'myapp2': None,
}
我有带 django-tenant 插件的 django 应用程序 2.1.7(在数据库中为 saas 创建模式)。
我的问题是单元测试。我 运行 命令:
python manage.py test --settings=project.settings_test
我收到一个错误:ImportError: No module named 'notmigrations'
我的代码在 settings_test 文件中
from .settings_base import *
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return 'notmigrations'
MIGRATION_MODULES = DisableMigrations()
您正在使用一个古老的 hack,用于真正旧版本的 Django (< 1.9),在测试中支持禁用迁移之前。由于您现在使用的是相对较新版本的 Django (2.1.7),因此请从您的测试设置模块中删除该代码。
如果您想在测试中禁用迁移,请使用 the modern approach, which is putting the value to None
in MIGRATION_MODULES
setting。
When you supply
None
as a value for an app, Django will consider the app as an app without migrations regardless of an existing migrations submodule. This can be used, for example, in a test settings file to skip migrations while testing (tables will still be created for the apps’ models).
# test_settings.py
from settings import *
MIGRATION_MODULES = {
'auth': None,
'contenttypes': None,
'sessions': None,
...
'myapp1': None,
'myapp2': None,
}