You cannot call instance methods from class methods. Either consider using setUp , or make the setup_test_data class method. Itβs also better if you called cls instead of self to avoid confusion - the first argument to the class method is the class, not the instance. An instance ( self ) does not exist at all when calling setUpClass .
class TestSystemPromotion(unittest2.TestCase): @classmethod def setUpClass(cls): cls.setup_test_data() @classmethod def setup_test_data(cls): ... def test_something(self): ...
Or:
class TestSystemPromotion(unittest2.TestCase): def setUp(self): self.setup_test_data() def setup_test_data(self): ... def test_something(self): ...
For a better understanding, you can think of it this way: cls == type(self)
source share