As a unit test, I would like to be able to test that the imports defined in a bunch of GUI screens make sense programatically. I don't want to have to execute anything, just
import main_screen
and see if anything falls over during the chain of imports. I've got as far as using the sys.modules trick:
import my_fake_module
sys.modules['module_i_want_to_fake'] = my_fake_module
Which works great, up until something does:
from module_i_want_to_fake import real_attribute
Then of course I get an ImportError unless I add a stubbed out method/class to my_fake_module, but there are way too many to make this practical.
Is there some way to hook imports from my_fake_module so that they always succeed? Again, they don't need to do anything. I bet there's a simple way but it's escaping me at the moment...