I have lots of files that are used in tests and I would like to define them in a class, so my editor can resolve it.
class Fixtures:
file_a = 'file_a.json'
file_b = 'file_b.json'
file_c = 'file_c.json'
def __getattribute__(self, name):
filename = getattr(Fixtures, name)
with open(filename, encoding='utf-8') as f:
return json.load(f, encoding='utf-8')
Now I can request a file using
Fixtures().file_a # returns content of file_a.json
However, these are class attributes (not instance attributes), but if I request it as such, __getattribute__ does not get called
Fixtures.file_a # returns string "file_a.json"
Is there a way to use the attributes as such, without having to instantiate first?