Full code example:
def decorator(class_):
class Wrapper:
def __init__(self, *args, **kwargs):
self.instance = class_(*args, **kwargs)
@classmethod
def __getattr__(cls, attr):
return getattr(class_, attr)
return Wrapper
@decorator
class ClassTest:
static_var = "some value"
class TestSomething:
def test_decorator(self):
print(ClassTest.static_var)
assert True
When trying to execute test, getting error:
test/test_Framework.py F
test/test_Framework.py:37 (TestSomething.test_decorator)
self = <test_Framework.TestSomething object at 0x10ce3ceb8>
def test_decorator(self):
> print(ClassTest.static_var)
E AttributeError: type object 'Wrapper' has no attribute 'static_var'
Is it possible to access static fields from the decorated class?
TestSomething
class is not necessary for this question, so I removed it. – Sloth__getattr__
should not be used in class context. The issue is obvious. TheWrapper
is not derived fromClassTest
– Luxate