@contextmanager
def use_step_import_modules(step_container):
 orig_modules = {}
 import_context = StepImportModuleContext(step_container)
 with _step_import_lock:
  try:
   for (module_name, fake_module) in six.iteritems(import_context.modules):
    orig_module = sys.modules.get(module_name, unknown)
    orig_modules[module_name] = orig_module
    sys.modules[module_name] = fake_module
   (yield import_context)
  finally:
   for (module_name, orig_module) in six.iteritems(orig_modules):
    if (orig_module is unknown):
     del sys.modules[module_name]
    else:
     sys.modules[module_name] = orig_module

@ contextmanager def use_step_import_modules ( step_container ) : orig_modules = { } import_context = StepImportModuleContext ( step_container ) with _step_import_lock : try : for ( module_name , fake_module ) in six . iteritems ( import_context . modules ) : orig_module = sys . modules . get ( module_name , unknown ) orig_modules [ module_name ] = orig_module sys . modules [ module_name ] = fake_module ( yield import_context ) finally : for ( module_name , orig_module ) in six . iteritems ( orig_modules ) : if ( orig_module is unknown ) : del sys . modules [ module_name ] else : sys . modules [ module_name ] = orig_module
redirect any step/type registration to the runners step-context object during step imports by using fake modules .