More Python mocking: dictionary

In previous post we look at how basic mocking works and some examples. Today we will see how you can mock dict :

post = {
    "name": "test",
    "content": "tist",
data = mock.MagicMock()
data.__getitem__.side_effect = lambda key: post[key]

If we copy paste this into interpreter we can check the results:

>>> data["name"]
>>> 'test'

Happy testing …


Leave a Reply

Your email address will not be published. Required fields are marked *