My code:
class TestSystemPromotion(unittest2.TestCase):
@classmethod
def setUpClass(self):
...
self.setup_test_data()
..
def test_something(self):
...
def setup_test_data(self):
...
if __name__ == '__main__':
unittest2.main()
Error which I’m getting is:
TypeError: unbound method setup_test_data() must be called with TestSystemPromotion
instance as first argument (got nothing instead)
You can’t call instance methods from class methods. Either consider using
setUpinstead, or makesetup_test_dataa class method too. Also, it’s better if you called the argumentclsinstead ofselfto avoid the confusion – the first argument to the class method is the class, not the instance. The instance (self) doesn’t exist at all whensetUpClassis called.Or:
For better comprehension, you can think of it this way:
cls == type(self)