question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow a mock to pass an issubclass test or to be used as the second argument to isinstance (by providing __bases__)

See original GitHub issue
For 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:closed
  • Created 8 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
voidspacecommented, Apr 30, 2019

I didn’t yet. I don’t think it will be very hard. Hopefully I can do it in the PyCon sprints.

0reactions
voidspacecommented, Sep 10, 2019

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found