Robert Collins added the comment:

So its a feature of mock that it can mock a module that doesn't exist. And the 
semantics of the import system are designed to be very cheap when a module is 
already imported - so when 'patchbug.a' is in sys.modules, import will 
correctly return it rather than going out to the import path to find if its the 
same thing.

We could possibly have an opt-in check on mock.patch to require that the thing 
being patched exists, but it would have to be opt-in as so many cases are 
dealing with optional or pretend instances. I'm not super keen on that though.

This is perhaps worth calling out in the docs to avoid confusion.

----------
nosy: +rbcollins

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

Reply via email to