magicmock的一个子类,它复制参数
copyingmock的Python项目详细描述
MagicMock用于具有可变参数的函数时有问题。这在documentation:
Another situation is rare, but can bite you, is when your mock is called with mutable arguments. ^{tt2}$ and ^{tt3}$ store references to the arguments. If the arguments are mutated by the code under test then you can no longer make assertions about what the values were when the mock was called.
然后他们提出了一个解决办法,使用side_effect,但这不是很讨人喜欢。还提供了一个优雅的配方,可以在调用时复制参数。它只是MagicMock的一个子类,复制参数,而不是存储引用。我不知道为什么配方没有直接包含在mock中,所以这里它是作为第三方包提供的。