[TIP] mock.ANY not actually ANY?

Michael Foord michael at voidspace.org.uk
Mon Jan 9 16:26:14 PST 2012


On 10/01/2012 00:16, Michael Foord wrote:
> On 09/01/2012 22:41, Tom Davis wrote:
>> I have a mock that is using assert_called_with() and mock.ANY thus:
>>
>> m = mock.Mock()
>> do_stuff(m)
>> m.assert_called_with(now=mock.ANY, foo='bar')
>>
>> Unfortunately, this results in:
>>
>> AssertionError: Expected call: mock(now=<ANY>, foo='bar')
>> Actual call: mock(now=datetime.datetime(2012, 1, 9, 22, 36, 41, 
>> 264838), foo='bar')
>>
>> I could have sworn that ANY used to work perfectly fine when used in 
>> this way. Is this a datetime thing or...?
>>
>> Using mock==dev
>
> Hmmm... dammit. I see the same thing, but I think I see the cause of 
> the problem:
>

Fixed on trunk. I'll do a 0.8rc2 release shortly including this fix.

Michael

> >>> from mock import Mock, ANY
> >>> from datetime import datetime
> >>> d = datetime.now()
> >>> m = Mock()
> >>> m(d)
> <Mock name='mock()' id='4312271632'>
> >>> m.assert_called_with(ANY)
> Traceback (most recent call last):
>  ...
> AssertionError: Expected call: mock(<ANY>)
> Actual call: mock(datetime.datetime(2012, 1, 10, 0, 13, 52, 593795))
> >>> ANY == d
> True
> >>> d == ANY
> False
>
> It only happens with certain types:
>
> >>> m(3)
> <Mock name='mock()' id='4312271632'>
> >>> m.assert_called_with(ANY)
> >>>
>
> I'll try and fix this, thanks for the report.
>
> All the best,
>
> Michael Foord
>>
>>
>> _______________________________________________
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
>> http://lists.idyll.org/listinfo/testing-in-python
>
>
> -- 
> http://www.voidspace.org.uk/
>
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
> -- the sqlite blessinghttp://www.sqlite.org/different.html
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python


-- 
http://www.voidspace.org.uk/

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120110/ae09082c/attachment-0001.htm>


More information about the testing-in-python mailing list