Sometimes, you want to assert that an object was called with some arguments, but the exact value for an argument is computed by some external logic that you do not want your test to depend on. Let's say it is generated by a template, and in this particular case you do not want changes to the template to break your test.


Let's say we mocked out service and want to make sure perform_action got called with a non-empty value for content. An easy way to do this with Python's mock library is to use the call_args attribute of the mock object:

args, kwargs = myobject.service.perform_action.call_args
self.assertTrue('data' in kwargs)

So, don't limit yourself to assert_called_with and friends. For many more interesting details on how to inspect mock calls in various ways, see the mock documentation.