我无法测试分组在子文件夹中的django应用程序。
好吧,让我解释一下情况。
Standart django项目结构如下:
django_project/
--appname1
--appname2
--appname3
--lib
--tests
--docs
settings.py
etc...
当项目结构为standart时,只需在project dir中键入命令,就可以运行appname1的测试:
python2 manage.py test appname1`
我们决定将所有应用程序放在子目录中,因此我们的项目结构如下:
django_project/
--apps/
----appname1
----appname2
----appname3
--lib
--tests
--docs
settings.py
etc...
一切正常,但我们无法运行应用程序测试。 我试过以下命令但没有成功:
python2 manage.py test appname1
python2 manage.py test apps/appname1
python2 manage.py test apps.appname1
对于放置在子文件夹中的应用程序,是否可以使用manage.py运行测试,或者我们应该编写自己的命令来运行它们?
升级版:
我们有以下错误:
Traceback (most recent call last):
File "manage.py", line 18, in <module>
management.execute_manager(settings)
File "/opt/python266/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/opt/python266/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python266/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/python266/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/opt/python266/lib/python2.6/site-packages/django/core/management/commands/test.py", line 37, in handle
failures = test_runner.run_tests(test_labels)
File "/opt/python266/lib/python2.6/site-packages/django/test/simple.py", line 312, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/opt/python266/lib/python2.6/site-packages/django/test/simple.py", line 244, in build_suite
app = get_app(label)
File "/opt/python266/lib/python2.6/site-packages/django/db/models/loading.py", line 140, in get_app
raise ImproperlyConfigured("App with label %s could not be found" % app_label)
django.core.exceptions.ImproperlyConfigured: App with label appname1 could not be found
我们已安装应用程序设置,如:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'project_name.apps.appname1',
'project_name.apps.appname2',
'project_name.apps.appname3',
)
你的应用文件夹下需要这两个文件:
它们可以是空的。
注意,settings.py文件包含一个元组,因此终止字符应该是“)”而不是“}”
你犯了什么错误?你在
settings.py
的INSTALLED_APPS
下面有什么?如果你有
在
apps
目录中的__init__.py
则应该可以工作。相关问题 更多 >
编程相关推荐