Hello people,
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 __init__
file of the package.
So here is the script I have so far:
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
If I use modulename = __import__(module)
the classes get added to the module 'modulename' and not the main namespace.
My question is, how do I import them to the current namespace?
So I can do things like:
testcase = TestCase()
testcase.run()
results = testcase.results()
or whatever in the main script without explicitly importing the classes.
Thanks in advance!
Thank you all for replying and trying to help me out.