回溯:
./manage.py test my_app
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/zuber/projects/private-CR/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/zuber/projects/private-CR/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/zuber/projects/private-CR/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/zuber/projects/private-CR/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 381, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
File "/home/zuber/projects/private-CR/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 354, in create_parser
self.add_arguments(parser)
File "/home/zuber/projects/private-CR/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 52, in add_arguments
test_runner_class = get_runner(settings, self.test_runner)
File "/home/zuber/projects/private-CR/env/local/lib/python2.7/site-packages/django/test/utils.py", line 152, in get_runner
test_module = __import__(test_module_name, {}, {}, force_str(test_path[-1]))
ImportError: No module named simple
我尝试从app文件夹中删除 init .py,然后我有“没有名为app_name的模块”。当我从项目文件夹中删除 init .py时 - 控制台说“没有模块命名设置”。如何测试我的应用程序?
答案 0 :(得分:3)
首先,您需要将两个__init__.py
放回到找到它们的位置。它们允许您从该模块导入内容。其次,你应该在manage.py
中发布代码,这样我们就可以更好地了解发生了什么,但在我看来,就像你在那里有一行类似于import django.contrib.admin.util
或{{1 }}。此模块已在您正在使用的django版本中删除,因此您应将import <something> from django.contrib.admin.util
的所有符号替换为django.contrib.admin.util
。
答案 1 :(得分:1)
我通过删除
解决了这个问题TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'
来自settings.py
答案 2 :(得分:0)
在我使用Pycharm时,问题在于PyCharm测试运行程序与Django 2.0不兼容
解决方案是: 将行254:EOF替换为
if VERSION[1] > 1 or VERSION[0] > 1:
return DjangoTeamcityTestRunner(**options).run_tests(test_labels,
extra_tests=extra_tests, **options)
return run_the_old_way(extra_tests, options, test_labels, verbosity)
代替:
if VERSION[1] > 1:
return DjangoTeamcityTestRunner(**options).run_tests(test_labels,
extra_tests=extra_tests, **options)
return run_the_old_way(extra_tests, options, test_labels, verbosity)