I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work.
A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid breaking a lot of code and get all kinds of exception from MyApp.
I am using Python and It should be something like:
“Import ResourceXSimulated as ResourceX”
“ResourceX.getData()”, actually calls ResourceXSimultated.getData()
Looking forward to find out if Python supports this kind of redirection.
Cheers.
ADDITIONAL INFO: I have access to the source files.
UPDATE: I am thinking of adding as little code as possible to MyApp regarding using the fake module and add this code near the import statements.
Just change all lines
import ResourceXinMyApptoimport ResourceXSimulated as ResourceX, and lines likefrom ResourceX import Ytofrom ResourceXSimulated import Y.However if don’t have access to
MyAppsource or there are other reasons not to change it, you can put your module intosys.modulesbeforeMyAppis loaded itself:Note: if
ResourceXis a package, it might require more effort.