In assert_called_once_with
, how can I specify a parameter is "any instance of class Foo"?
For example:
class Foo(): pass
def f(x): pass
def g(): f(Foo())
import __main__
from unittest import mock
mock.ANY
of course passes:
with mock.patch.object(__main__, 'f') as mock_f:
g()
mock_f.assert_called_once_with(mock.ANY)
and of course, another instance of Foo doesn't pass.
with mock.patch.object(__main__, 'f') as mock_f:
g()
mock_f.assert_called_once_with(Foo())
AssertionError: Expected call: f(<__main__.Foo object at 0x7fd38411d0b8>)
Actual call: f(<__main__.Foo object at 0x7fd384111f98>)
What can I put as my expected parameter such that any instance of Foo will make the assertion pass?