Python modules matching a pattern
<p>I'd like to run <code>doctest</code>s for a set of modules (glob: <code>invenio.webtag*</code>) from a single module, but I'll need a way to import all these (and only these) modules and run <code>doctest.testmod()</code> on all of them. Any ideas?</p>

<p><strong>Edit</strong>: The solution:</p>

<pre><code>import doctest
import glob
import os
import pkgutil
pkgpath = pkgutil.extend_path([], 'invenio')[0]
for module_path in glob.glob(pkgpath + '/webtag*.py'):
    module_name = os.path.splitext(os.path.basename(module_path))[0]
    module = __import__('invenio.' + module_name)
    doctest.testmod(module)
</code></pre>
