isinstance support

233 views
Skip to first unread message

Chris

unread,
Apr 18, 2011, 4:35:07 AM4/18/11
to mockito-python
Hello,

I'm a bit new to python, but it seems to me that this should work:

assert isinstance(mock(SomeClass), SomeClass)

but it fails. Should this pass, or is my assumption wrong?

Cheers,
Chris

r.

unread,
Jan 30, 2012, 9:26:29 AM1/30/12
to mockito...@googlegroups.com
Maybe not too late for an answer, your assumption is wrong : a mock is not an instance of a type, it only emulates such instance.

>>> from mockito import mock
>>> class SomeClass(object): pass

>>> type(mock(SomeClass))
<class 'mockito.mocking.mock'>

r.

danielja...@gmail.com

unread,
Aug 23, 2013, 9:38:54 AM8/23/13
to mockito...@googlegroups.com
Hi,

Is there a way to 'mock' the instance type? I have some functions which check for the argument types. I can't test them because they fail 'isinstance' checks when I pass in mocked objects.

Thanks,

Dan

Raphael MARVIE

unread,
Aug 23, 2013, 4:16:45 PM8/23/13
to mockito...@googlegroups.com

Hi,

Checking for argument type with a isinstance is a bad smell. You should
not test argument types, but use polymorphism instead.

r.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "mockito-python" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mockito-python/MfUPBPb98PI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> mockito-pytho...@googlegroups.com.
> To post to this group, send email to mockito...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mockito-python.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Réduire, réutiliser, recycler, repenser
Reduce, reuse, recycle, rethink
Reply all
Reply to author
Forward
0 new messages