Allow a mock to pass an issubclass test or to be used as the second argument to isinstance (by providing __bases__)
See original GitHub issueFor example:
{{{
>>> class foo(object):
... @property
... def __bases__(self):
... return (int,)
...
>>> a = foo()
>>> issubclass(a, int)
True
}}}
Original issue reported on code.google.com by fuzzyman on 1 Mar 2011 at 12:05
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
mock — pythonfmask 0.5.7 documentation
This allows mocks to pass `isinstance` tests. * `spec_set`: A stricter variant of `spec`. If used, attempting to *set* or get an attribute...
Read more >isinstance and Mocking - python - Stack Overflow
In your example you can just create a Mock to use as HelloWorld object, use spec argument to dress it as HelloWorld instance...
Read more >Python issubclass() - GeeksforGeeks
Python issubclass() is built-in function used to check if a class is a subclass of another class or not. This function returns True...
Read more >mock.mock — webapp2 3.0.0b1 documentation
This allows mocks to pass `isinstance` tests. * `spec_set`: A stricter variant of `spec`. If used, attempting to *set* or get an attribute...
Read more >brython.info/src/Lib/unittest/mock.py
Use a spec " f"for the mock if {name!r} is meant to be an attribute.") result = self. ... This allows mocks to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I didn’t yet. I don’t think it will be very hard. Hopefully I can do it in the PyCon sprints.
Passing an issubclass check is very hard to mock out. For issubclass(bar, Foo) there’s nothing you can do on bar or type(bar) (where bar is a mock object) to make it pass. You could mess with Foo to override
__subclasscheck__but that’s not what we want to achieve (and not possible if Foo is a built-in type).Overriding issubclass is a better approach and you can already do that.