Nick Coghlan added the comment:

While it *may* be possible to do something simpler for test purposes where 
performance isn't a major concern, fully supporting type() level mocking 
basically requires bringing the equivalent of wrapt object proxies into the 
standard library: 
https://wrapt.readthedocs.io/en/latest/wrappers.html#object-proxy

I actually think we *should* do that, and occasionally bug Graham Dumpleton 
about it, but while he's not opposed to the idea, it's also something that 
would take quite a bit of work (since odd edge cases that are tolerable in an 
opt-in third party module would probably need to be addressed for a standard 
library version).

For test cases like AsyncExitStack though, we instead just use custom type 
definitions, rather than the unittest.mock module.

Autospec'ed mocks are most attractive when we're dealing with object interfaces 
that are subject to a high rate of churn (since they make the tests more 
self-adjusting), and that isn't the case here: Python's syntactic support 
protocols rarely change, and when they do, preserving backwards compatibility 
with existing classes is typically a key requirement.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to