2012-02-13 10 views
2

以下の構造のかなり複雑なdjangoアプリケーションがあります。djangoアプリケーションのカスタムテストスイート

/myapp 
/myapp/obj1/.. 
/myapp/obj1/views.py 
/myapp/obj1/forms.py 
/myapp/obj2/.. 
/myapp/obj2/views.py 
/myapp/obj2/forms.py 
/myapp/tests/.. 
/myapp/tests/__init__.py 
/myapp/tests/test_obj1.py 
/myapp/tests/test_obj2.py 

私はもっと多くのオブジェクトを持っています。 /myapp/tests/__init__.pyではtest_obj1.pytest_obj2.pyからTestCaseのインスタンスをインポートし、使用可能なすべてのテストを実行するだけで十分です。

私がしようとしているのは、カスタムテストスイートを作成することです。ドキュメントによると:だから

There is a second way to define the test suite for a module: if you define a function called suite() in either models.py or tests.py, the Django test runner will use that function to construct the test suite for that module. This follows the suggested organization for unit tests. See the Python documentation for more details on how to construct a complex test suite.

、私はこのようなこの機能を作成しました:

def suite(): 
    suite = unittest.TestSuite() 
    suite.addTest(TestObj1Form()) 
    suite.addTest(TestObj2Form()) 
    return suite 

私がテストを実行するときしかし、私はこのエラーを取得:ValueError: no such test method in <class 'myproject.myapp.tests.test_obj1.TestObj1Form'>: runTest。もちろん、私はこのメソッドを定義することができますが、テストを実行すると、このメソッドだけが呼び出され、test*メソッドはすべて無視されます。

djangoアプリケーションのカスタムテストスイートを正しく作成する方法を教えてください。私はグーグルで、私はそれについて何も見つかりませんでした。

答えて

2

あなたは特別な機能をすべてのテストを追加する必要があります

suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestObj1Form)) 
+0

おかげで、それが動作します。 –

関連する問題