title: Ignore ImportError when exec source code
body: <p>I have an application that reads test scripts in python and sends them across the network for execution on a remote python instance.  As the controlling program does not need to run these scripts I do not want to have all the modules the test scripts use installed on the controller's python environment.  However the controller does need information from the test script to tell it how to run the test.
  Currently what I do to read and import test script data is something like</p>
  
  <pre><code>with open( 'test.py', 'r' ) as f:
      source = f.read()
  
  m = types.ModuleType( "imported-temp", "Test module" )
  co = compile( source, 'test.py', 'exec' )
  
  exec co in m.__dict__
  </code></pre>
  
  <p>which yields a new module that contains the test.  Unfortunately exec will raise ImportErrors if the test tries to import something the controller does not have.  And worse, the module will not be fully imported.</p>
  
  <p>If I can guarantee that the controller will not use the missing modules, is there someway I can ignore these exceptions?  Or some other way to find out the names and classes defined in the test?</p>
  
  <p>Examples test:</p>
  
  <pre><code>from controller import testUnit
  import somethingThatTheControllerDoesNotHave
  
  _testAttr = ['fast','foo','function']
  
  class PartOne( testUnit ):
      def run( self ):
          pass
  </code></pre>
  
  <p>What the controller needs to know is the data in _testAttr and the name of all class definitions inheriting from testUnit.</p>