Documentation
I always assumed that unittest.mock.patch.dict made a recursive (deep) copy of the dict and restored it afterwards.
It turns out it is a "simple" copy()
We should maybe clarify that in the documentation
Example:
foo = {
"bar": {"baz": 1}
}
with patch.dict(foo, {"unrelated": 123}):
foo["bar"]["baz"] = 2
# baz will stay at 2, assumed it was reset to the original 1
Linked PRs