如何测试django应用程序放在子文件夹? [英] How to test django application placed in subfolder?
问题描述
我在测试分组在子文件夹中的django应用程序有问题。
I have problem with testing django apps grouped in subfolder.
嗯,让我解释一下。
Standart django项目结构如下所示:
Standart django project structure looks like this:
django_project/
--appname1
--appname2
--appname3
--lib
--tests
--docs
settings.py
etc...
当项目结构标准化时,您可以通过在项目dir中键入命令来运行appname1的测试:
When project structure is standart you can run tests for appname1 just by typing command in project dir:
python2 manage.py test appname1`
我们决定把所有的应用程序放在subfloder中,所以我们的项目结构看起来像这样:
We decided to put all apps in subfoloder, so our project structure looks like this:
django_project/
--apps/
----appname1
----appname2
----appname3
--lib
--tests
--docs
settings.py
etc...
一切正常,但我们无法运行应用程序测试。
我已经尝试过没有成功的命令:
All works fine, but we can't run tests for apps. I have tried folowing commands without success:
python2 manage.py test appname1
python2 manage.py test apps/appname1
python2 manage.py test apps.appname1
有没有办法运行测试使用manage.py为应用程序放在子文件夹,或者我们应该编写自己的命令来运行它们?
Is there any way for running tests using manage.py for apps that placed in subfolder, or we should write own command for running them?
UPD:
我们有以下错误:
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
我们已经安装了如下设置:
We have installed apps setting like:
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',
)
推荐答案
您需要这两个文件在您的应用程序文件夹下:
You need both these files under your app folder:
__init__.py
models.py
它们可以是空的。
这篇关于如何测试django应用程序放在子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!