1class HauntedMansion:
2 """Scares you"""
3
4 def __init__(self, **kwargs):
5 for key, value in kwargs.items():
6 setattr(self, key, value)
7
8 def __getattribute__(self, name):
9 if 'spooky_' == name[:7]:
10 return super().__getattribute__(name[7:])
11 elif '__' == name[:2]:
12 return super().__getattribute__(name)
13 else:
14 return 'Booooo, only ghosts here!'
E
======================================================================
ERROR: test_haunted_mansion (test.TestHauntedMansion.test_haunted_mansion)
The mansion should be really spooky and haunted.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 25, in test_haunted_mansion
self.assertEqual(haunted_mansion.spooky_buttler, "Booooo, only ghosts here!")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 10, in __getattribute__
return super().__getattribute__(name[7:])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'HauntedMansion' object has no attribute 'buttler'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
02.11.2024 20:53