如何测试放置在子文件夹中的 django 应用程序?

2024-03-22

我在测试分组在子文件夹中的 django 应用程序时遇到问题。

好吧,让我解释一下情况。

标准 django 项目结构如下所示:

django_project/
--appname1
--appname2
--appname3
--lib
--tests
--docs
settings.py 
etc...

当项目结构是标准的时,您只需在项目目录中键入命令即可运行 appname 1 的测试:

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 来运行放置在子文件夹中的应用程序的测试,或者我们应该编写自己的命令来运行它们?

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

我们已经安装了应用程序设置,例如:

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',
 )

您的应用程序文件夹下需要这两个文件:

__init__.py
models.py

它们可以是空的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何测试放置在子文件夹中的 django 应用程序? 的相关文章

随机推荐