I know you can define data descriptors for a class instance using the __get__
and __set__
methods. Is it possible to define something similar for an imported module ?
Use case:
I have a large test file with a lot of dictionaries defined in a
test_data.py
(legacy code), therefore all of them are **mutable and cannot be modified by individual tests without using deepcopy
I want to be able to modify these dictionaries
- Without re-writing the data into classes
- without calling deepcopy in tests.
Test data:
expected_response_1 = dict(status=False)
Test case:
from test import test_data
data = test_data.expected_response_1
data['status'] = True
print(data)
# --> {'status': True}
print(test_data.expected_response_1)
# --> {'status': False}
Is there any *python-magic i can use to always return a copy of expected_response_1