As you've probably noticed, when we use dummy objects, stubs, or spies, we always end up working with the unittest.mock module. That's because mock objects could be seen as dummy objects that provide some stubs mixed with spies.
Mocks are able to be passed around and they usually do nothing, behaving pretty much like dummy objects.
If we had a read_file function accepting a file object with a read method, we could provide a Mock instead of a real file; Mock.read will just do nothing:
>>> def read_file(f):
... print("READING ALL FILE")
... return f.read()
...
>>> from unittest.mock import Mock
>>> m = Mock()
>>> read_file(m)
READING ALL FILE
If instead of doing nothing, we want to make it act like a stub, we can provide a canned response to have Mock.read return a predefined string:
>>> m.read.return_value = "Hello World"
>>> print(read_file(m))
Hello World
If we don't want to just fill...