You cannot use super(myClass, self)
within a decorated class in this way.
myClass
is looked up as a global, and the global myClass
is rebound to Decorator
, so you are telling Python to look in the class MRO for __init__
starting from Decorator
which is myClass
, which calls super(myClass, self).__init__()
, looking up myClass
as a global, which is bound to Decorator
, etc.
The easiest work-around is to not use super()
here:
@decorator
class myClass(unittest.TestCase):
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
self.test = 'test'
This is one of the reasons why in Python 3 the argument-less version of super()
was introduced, giving methods a __class__
cell instead.
You could jump through some (very tricky) hoops to re-compile the myClass.__init__()
method to give it a myClass
closure bound to the original undecorated class object instead, but for a unittest, I would not bother.