无法为Django创建测试套件
问题描述:
我在Django 1.3中创建测试套件时遇到问题。无法为Django创建测试套件
假设我在一个名为app_name
的目录中安装了应用程序。该目录中的一个文件是foo.py
,它定义了一个名为Foo
的类。我想测试一下,所以我也有一个名为foo_test.py
的文件,它定义了一个名为FooTest
的类。这个文件看起来像:
import unittest
import foo
class FooTest(unittest.TestCase):
def setUp(self):
self.foo_instance = foo.Foo()
... etc
现在下了线,我会在其他文件的其他测试案例,我将要运行它们都作为一个测试套件的一部分。所以在同一个目录app_name
我创建了一个文件tests.py
它将定义套件。起初,我定义它想:
import foo_test
from django.test.simple import DjangoTestSuiteRunner
def suite():
runner = DjangoTestSuiteRunner()
return runner.build_suite(['app_name'])
不幸的是,这种失败,因为调用runner.build_suite(['app_name'])
搜索app_name
一个tests.py
文件,执行suite()
了,这样下去直到递归Python解释为超过最大递归深度停止一切。
更改runner.build_suite(['app_name'])
到
runner.build_suite(['app_name.foo_test'])
或
runner.build_suite(['app_name.foo_test.FooTest'])
导致像ValueError: Test label 'app_name.foo_test' does not refer to a test
错误。
而且将其更改为:
runner.build_suite(['foo_test'])
或
runner.build_suite(['foo_test.FooTest'])
导致像App with label foo_test could not be found
错误。
在这一点上我有种想法。任何帮助将非常感激。谢谢!