我发现python内部处理字典对象与其他对象不同,如function和list。
有没有人知道为什么python模拟库(1.0.1)除了现有的补丁和patch.object之外还有一个patch.dict?
答案 0 :(得分:1)
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()
使用patch.dict(foo,{' newkey':' newvalue'},clear = True):
断言foo == {' newkey':' newvalue'}
断言foo ==原始
请参阅reference