*spec_set* instead of *spec*.
+Using side_effect to return per file content
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+:func:`mock_open` is used to patch :func:`open` method. :attr:`~Mock.side_effect`
+can be used to return a new Mock object per call. This can be used to return different
+contents per file stored in a dictionary::
+
+ DEFAULT = "default"
+ data_dict = {"file1": "data1",
+ "file2": "data2"}
+
+ def open_side_effect(name):
+ return mock_open(read_data=data_dict.get(name, DEFAULT))()
+
+ with patch("builtins.open", side_effect=open_side_effect):
+ with open("file1") as file1:
+ assert file1.read() == "data1"
+
+ with open("file2") as file2:
+ assert file2.read() == "data2"
+
+ with open("file3") as file2:
+ assert file2.read() == "default"
+
Patch Decorators
----------------