2011-01-18 6 views
3

Pythonでユニットテストにunittestとnoseを使用しましたが、今はpy.testを使用しています。
unittestとnoseは、TestCaseのすべてのメソッドを実行する前に常にclass.setUpを呼び出します。py.testすべてのテストの前にメソッドを実行する方法

py.testでこれを行うにはどうすればよいですか?

EDIT:

_____________________________ TestPolynomial.testSetitem ______________________________ 

self = <test_pypol.TestPolynomial object at 0x97355ec> 

    def testSetitem(self): 
>  TestPolynomial.a[2] = (3, {'x': 3, 'y': 4}) 
E  AttributeError: type object 'TestPolynomial' has no attribute 'a' 

test_pypol.py:162: AttributeError 
_____________________________ TestPolynomial.testDelitem ______________________________ 

self = <test_pypol.TestPolynomial object at 0x9735eac> 

    def testDelitem(self): 
>  del TestPolynomial.a[1:3] 
E  AttributeError: type object 'TestPolynomial' has no attribute 'a' 

はEDIT2:[OK]を、私は愚かだ、私はすべてのエラーを取得

def setup_class(cls): 
    cls.a = pypol.polynomial('x^3 - 2x^2 + x -5') 
    cls.b = pypol.polynomial('a^3 - 2x^2 - b + 3') 
    cls.c = pypol.polynomial('-x + 1') 
    cls.d = pypol.polynomial('a') 

:私はこれを追加する場合。私はTestCaseの中に入れなければなりませんでした。ありがとうございました。

答えて

関連する問題