mock-import
mock-import copied to clipboard
Add mock for hiding existing import
If an library has already been imported, or does exist and can be imported, it can be hard to test what happens when the import fails.
This is commonly needed for optional imports, where the code runs slightly differently if the import fails, or for platform specific imports, where the functionality can be tested for a different platform is able to be tested if the import fails. e.g. "what happens if pyreadline was not installed because the platform is not Windows."
Hi, I didn't understand specifically what you mean. Maybe you can provide an example for what is missing for you? Thanks
The opposite of what you are doing in this library ;-)
import argcomplete # only to show it works when already imported
from mock import Mock, patch
def foo():
import argcomplete
argcomplete.autocomplete()
fake_importer = Mock(side_effect=ImportError('fake import missing'))
with patch('builtins.__import__', new=fake_importer):
foo()
Nice! Sounds like a cool feature to develop! You want to code it?
Sure.
On Sun, Jul 22, 2018, 18:10 Eyal Posener [email protected] wrote:
Nice! Sounds like a cool feature to develop! You want to code it?
— You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/posener/mock-import/issues/17#issuecomment-406858021, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA69GYjW4aOEyafuHcgKBFo21NPwuZrks5uJF2QgaJpZM4VX7e- .