derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Mock.assert_has_calls doesn't work as expected (take 2) #191

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The documentation has the following example:

>>> mock = Mock(return_value=None)
>>> mock(1)
>>> mock(2)
>>> mock(3)
>>> mock(4)
>>> calls = [call(2), call(3)]
>>> mock.assert_has_calls(calls)

I would also expect the following to work:

>>> mock.assert_has_calls([call(2), call(4)])

I see that it doesn't, and that assert_has_calls expects you to provide all the 
middle calls you want to check. I don't find this behavior to be as useful as 
ignoring them. To me, the reason to use assert_has_calls is because it's useful 
for maintenance and clarity to not need to specify all the calls that are being 
performed on an object. There may be other calls being done that shouldn't fail 
the test, and having to specify all the other ones clutters the test and 
introduces ways for the test to break for poor reasons. So I'd expect 
assert_has_calls to ignore middle calls just like it ignores beginning and 
ending calls (in fact, I'd written assert_has_calls myself back in 0.7ish? to 
do just that before you told me that 0.8 was adding something similar, so if 
you're interested in this I probably still have that somewhere).

Original issue reported on code.google.com by jul...@grayvines.com on 25 Nov 2012 at 12:40

GoogleCodeExporter commented 9 years ago
I agree with the OP.  Order is a requirement, which is good.  

But, "has" is not the same as "has only" or "is equal".  Its a small but 
important distinction.  

Original comment by sean.m.o...@gmail.com on 26 Dec 2012 at 9:45