I am writing unit tests, and want to check for a call which has a function object, like so:
call(u'mock', u'foobar', <function <lambda> at 0x1ea99b0>, 10)
How do I check that the call() has all the parameters I want, without reproducing the lambda?
Edit: I wanted to clarify that I am using the mock
library from here: http://mock.readthedocs.org/en/latest/. The call
I showed above is a call on a MagicMock
object, which I want to check using assert_has_calls
.
I finally found out how to do what I want. Basically, when using assert_has_calls
, I wanted one parameter to match regardless of what it was (because I can't recreate the lambda
every time during test).
The way to do it is to use mock.ANY
.
So, in my example, this could match the call:
mocked_object.assert_has_calls([ call('mock', 'foobar', mock.ANY, 10) ])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With