属性错误: 类型对象'NoDbTestRunner'没有属性'split'



我正试图为Django 2.0和python3创建一个DiscoverRunner来跳过DB创建,但出现了以下错误:

File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/mlmireles/.virtualenvs/risk-analysis/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/mlmireles/.virtualenvs/risk-analysis/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mlmireles/.virtualenvs/risk-analysis/lib/python3.6/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "/home/mlmireles/.virtualenvs/risk-analysis/lib/python3.6/site-packages/django/core/management/base.py", line 280, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
File "/home/mlmireles/.virtualenvs/risk-analysis/lib/python3.6/site-packages/django/core/management/base.py", line 254, in create_parser
self.add_arguments(parser)
File "/home/mlmireles/.virtualenvs/risk-analysis/lib/python3.6/site-packages/django/core/management/commands/test.py", line 47, in add_arguments
test_runner_class = get_runner(settings, self.test_runner)
File "/home/mlmireles/.virtualenvs/risk-analysis/lib/python3.6/site-packages/django/test/utils.py", line 306, in get_runner
test_path = test_runner_class.split('.')
AttributeError: type object 'NoDbTestRunner' has no attribute 'split'

这是跑步者的代码:

from django.test.runner import DiscoverRunner
class NoDBTestRunner(DiscoverRunner):
def setup_databases(self, **kwargs):
pass
def teardown_databases(self, *args, **kwargs):
pass

在Django文档中的test_class_runner中,您会注意到这些设置。TEST_RUNNER需要一个由句点"."分隔的字符串。sting.split可以在python文档中找到(https://docs.python.org/3.7/library/stdtypes.html#str.split)

因此,在您的设置文件中,您应该设置TEST_RUNNER变量,如下所示:

TEST_RUNNER = 'yourapp.settings_file.NoDbTestRunner'

假设你的应用程序结构如下,并且你的NoDBTestRunner类也在settings_file.py文件中。如果类不是,只需将TEST_RUNNER的引用更改为指向NoDbTestRunner所在的位置。

  • 您的应用程序文件夹
    • settings_file.py#这个文件是您设置变量的地方

相关内容

  • 没有找到相关文章

最新更新