我正在开发一个 django 项目,其中有多个应用程序。每个应用程序都有一个测试目录,其中包含整个项目的测试。我的目录结构如下。
Project
App_1
tests
__init__.py
tests_views.py
App_2
tests
__init__.py
tests_views.py
settings.py
manage.py
我可以像这样运行测试
python manage.py test App_1.tests
它运行 App_1/tests/test_views.py 中的所有测试。但我必须为我项目中的所有应用程序执行此操作。我想要一个命令来运行我项目中所有应用程序中的所有测试。我试过跑步
python manage.py 测试
但我收到以下错误
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/srv/www/project/shared/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/srv/www/project/shared/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 "/srv/www/project/shared/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 "/srv/www/project/shared/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/srv/www/project/shared/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/srv/www/project/shared/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/srv/www/project/shared/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/srv/www/project/shared/env/local/lib/python2.7/site-packages/django/test/runner.py", line 209, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/srv/www/project/shared/env/local/lib/python2.7/site-packages/django/test/runner.py", line 150, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/usr/lib/python2.7/unittest/loader.py", line 204, in discover
tests = list(self._find_tests(start_dir, pattern))
File "/usr/lib/python2.7/unittest/loader.py", line 285, in _find_tests
for test in self._find_tests(full_path, pattern):
File "/usr/lib/python2.7/unittest/loader.py", line 265, in _find_tests
raise ImportError(msg % (mod_name, module_dir, expected_dir))
ImportError: 'tests' module incorrectly imported from '/vagrant/code/project/App_1/tests'. Expected '/vagrant/code/project/App_1'. Is this module globally installed?
谁能告诉我如何使用单个命令在我的应用程序中进行所有测试?