Mock an entire module in python
问题 I have an application that imports a module from PyPI. I want to write unittests for that application's source code, but I do not want to use the module from PyPI in those tests. I want to mock it entirely (the testing machine will not contain that PyPI module, so any import will fail). Currently, each time I try to load the class I want to test in the unittests, I immediately get an import error. so I thought about maybe using try: except ImportError: and catch that import error, then use