In setUp() method of unittest I\'ve setup some self variables, which are later referenced in actual tests. I\'ve also created a decorator to do some logging. Is the
Since you're decorating a method, and self
is a method argument, your decorator has access to self
at runtime. Obviously not at parsetime, because there are no objects yet, just a class.
So you change your decorator to:
def decorator(func):
def _decorator(self, *args, **kwargs):
# access a from TestSample
print 'self is %s' % self
return func(self, *args, **kwargs)
return _decorator