I want to set a conditional decorator to the setUpClass
in python's unitest. I have tried the following (without a condition for now, to demonstrate the point):
import unittest
class conditional_decorator(object):
def __call__(self, func):
print ("Extra output")
return func
class First(unittest.TestCase):
@classmethod
@conditional_decorator
def setUpClass(cls):
print ("setting up")
def test1(self):
pass
if __name__ == '__main__':
unittest.main()
but I get an error
TypeError: object.__new__() takes no parameters
How can I solve this problem? Moreover, is there an easy way to 'combine' the two decorators for the setUpClass
method?