title: python automatic (or dynamic) import classes in packages
body: <p>I'm writing some kind of automated test suite and I want to make sure the classes contained in the package 'tests' get imported automatically upon runtime in the main namespace, without adding them to the <code>__init__</code> file of the package.</p>
  
  <p>So here is the script I have so far:</p>
  
  <pre><code>import os
  
  for dirpath, dirnames, filenames in os.walk('tests'):
      for filename in filenames:
          if filename.lower().endswith(('.pyc', '__init__.py')): continue
  
          module = ".".join([dirpath, filename.split('.')[0]])
  
          print module
  </code></pre>
  
  <p>If I use <code>modulename = __import__(module)</code> the classes get added to the module 'modulename' and not the main namespace.</p>
  
  <p>My question is, how do I import them to the current namespace?</p>
  
  <p>So I can do things like:</p>
  
  <pre><code>testcase = TestCase()
  testcase.run()
  results = testcase.results()
  </code></pre>
  
  <p>or whatever in the main script without explicitly importing the classes.</p>
  
  <p>Thanks in advance!</p>
  
  <p>Thank you all for replying and trying to help me out.</p>