Running nosetests -s for
class TestTemp(): def __init__(self): print '__init__' self.even = 0 def setup(self): print '__setup__' self.odd = 1 def test_even(self): print 'test_even' even_number = 10 assert even_number % 2 == self.even def test_odd(self): print 'test_odd' odd_number = 11 assert odd_number % 2 == self.odd
displays the following.
__init__ __init__ __setup__ test_even .__setup__ test_odd .
Test instances are created before the tests run, and the installation is performed immediately before the test.
In general, __init__() and setup () do the same thing, but is there a drawback in using __init__() instead of setup ()? Or using both?
Tage nielsen
source share