How to unit test the code without having the depending modules available at all?
This happens often when you work with API libraries, which are provided as a part of an installed product. And worst of all, the development kits are only provided for the certain OS - but not for yours.
Unit testing and mocking is less painful when the API is based on objects and classes. If the depending module is static and has a state, unit tests end up being a bit of a mess.
Unit testing without the depending module
Assuming the following is the code you've created. You don't have the missing_module implementation around for the unit tests.
mocked.py
_____________________________________________
import missing_module
class ClassWithDependency:
def call_dependency(self):
try:
return missing_module.things.do()
except missing_module.Error as ne:
raise RuntimeError()
_____________________________________________