Argument matchers for unittest.mock
More robust tests
You can be either very specific:
my_mock.assert_called_once_with(42, some_foo_object, 'certain string')
or extremely general:
my_mock.assert_called_with(ANY, ANY, ANY) # passes as long as argument count is the same
callee provides argument matchers that allow you to be exactly as precise as you want:
my_mock.assert_called_with(GreaterThan(0), InstanceOf(Foo), String())
without tedious, handcrafted, and poorly readable code that checks
self.assertGreater(mock.call_args, 0) self.assertIsInstance(mock.call_args, Foo) self.assertIsInstance(mock.call_args, str)
It has plenty of matcher types to fit all common and uncommon needs, and you can easily write your own if necessary.
Installing callee is easy with pip:
$ pip install callee
unittest.mockmodule from Python 3.3+ or its backport.
See the documentation for complete reference on the library usage and all available matchers.
Contributions are welcome!
If you need ideas, head to the issue tracker or search for the various
TODOs scattered around the codebase.
Or just think what matchers you'd like to add :)
After cloning the repository, this should get you up and running:
# ... create virtualenv as necessary ... pip install -r requirements-dev.txt tox
To regenerate documentation and display it in the browser, simply run: