Skip to content

[docs] Specify that unittest.mock.patch.dict does not make a deepcopy #144433

@romuald

Description

@romuald

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir
    No fields configured for issues without a type.

    Projects

    Status

    Todo

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions