Ich habe unittest und nose für Unit-Tests in Python verwendet, aber jetzt benutze ich py.test.
unittest und nose rufen immer class.setUp
bevor jede Methode im TestCase ausgeführt wird.
Wie kann ich dies mit py.test erreichen?
EDIT: Wenn ich das hinzufüge:
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')
Ich erhalte alle Fehler:
_____________________________ 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, ich bin dumm. Ich musste innerhalb der TestCase setzen und nicht außerhalb. Dankeschön.