Why there is a patch.dict specifically
Question:
I have found that the python internal deals with dictionary object different as the other object like function and list.
Does anyone have idea why python mock library (1.0.1) has a patch.dict specifically besides the existing patch and patch.object?
Answers:
patch.dict()
for setting values in a dictionary just during a scope and restoring the dictionary to its original state when the test ends:
foo = {'key': 'value'}
original = foo.copy()
with patch.dict(foo, {'newkey': 'newvalue'}, clear=True):
assert foo == {'newkey': 'newvalue'}
assert foo == original
See the reference for further info.
I have found that the python internal deals with dictionary object different as the other object like function and list.
Does anyone have idea why python mock library (1.0.1) has a patch.dict specifically besides the existing patch and patch.object?
patch.dict()
for setting values in a dictionary just during a scope and restoring the dictionary to its original state when the test ends:
foo = {'key': 'value'}
original = foo.copy()
with patch.dict(foo, {'newkey': 'newvalue'}, clear=True):
assert foo == {'newkey': 'newvalue'}
assert foo == original
See the reference for further info.