Proper way to mock classes and assert on calls to methods
read
is a method on instances of Foo
. You want to check for the mock return_value
to access the instance. After all, you create the instance by calling foo.Foo()
:
foo_instance = self.foo_mock.return_value
foo_instance.read.assert_called_once_with('foo')
Note that you are patching foo.Foo
; using bar.foo.Foo
is the same object, but a round-about way of specifying it.