[TIP] mock.ANY not actually ANY?

Tom Davis tom at recursivedream.com
Mon Jan 9 17:41:18 PST 2012


On Mon, Jan 9, 2012 at 7:26 PM, Michael Foord <michael at voidspace.org.uk>wrote:

>  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.
>

Thanks Michael--for the great library and the always-prompt responses here
:)


>
>
> 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 listtesting-in-python at lists.idyll.orghttp://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
>
>
>
> _______________________________________________
> testing-in-python mailing listtesting-in-python at lists.idyll.orghttp://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/20120109/0e10a322/attachment.htm>


More information about the testing-in-python mailing list