I need to use a utility function that exists in an external module I do not control. The module has many imports that are not used by the specific function I care about. I don't want to install those unnecessary dependencies (and especially not bloat my packages dependency list).
It doesn't seem possible to use the function without the imports. I wondered if it's possible to mock the module? I had briefly hoped this would work:
""" module_a """
import unused_module
def f():
return something_of_value
""" module_b: needs to use module_a.f() but doesn't have unused_module installed. """
import mock_module as unused_module
global unused_module
import module_a
module_a.f()
But I couldn't inject my mock of unused_module. Is there a workaround I could use here?