def hasDependency(module, fake_module=None):
 import mock
 import sys
 if (fake_module is None):
  fake_module = mock.MagicMock()
 if fake_module:
  sys.modules[module] = fake_module

def hasDependency ( module , fake_module = None ) : import mock import sys if ( fake_module is None ) : fake_module = mock . MagicMock ( ) if fake_module : sys . modules [ module ] = fake_module
use this function in your test class setup to mock modules into your namespace .