I have a python file the imports certain modules that aren't easily testable on all systems. Just importing the module on macOS for example causes an exception. Is there a way to mock this. Essentially I want to change the source code on one line before actually running the import statement.
Test code
from module_a import func
def test_func():
print("...")
Module code
module_a.py
import os
import numpy as np
# ...
import magicmodulethatbreaksonmac
def func():
# Nothing inside this function needs magicmodulethatbreaksonmac
Would be great if in the test code, I could do some sort of mock on module_a.py
to not actually try to import magicmodulethatbreaksonmac
but rather just don't import anything as it's not needed to test this function.
Is there a way to put something of the same name in the namespace already that doesn't have anything in it so when it tries to import it again here, nothing happens? (If that is the behavior...)
I would think there's something here, but I'm not seeing it: https://docs.python.org/3/library/unittest.mock.html