I have a folder with all my unittests. They all include:
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())
So to test them I only have to import the test script. I have a test_all script that does all the unittests by importing them one by one. Currently this looks like this:
from pyMS.test import test_baseFunctions
from pyMS.test import test_compareFeatureXMLmzML
from pyMS.test import test_config
from pyMS.test import test_featureFunctions
from pyMS.test import test_fileHandling
from pyMS.test import test_mzmlFunctions
from pyMS.test import test_output
from pyMS.test import test_parseFeatureXML
from pyMS.test import test_rFunctions
from pyMS.test import test_rPlots
[...]
This means that every time I add or remove a new test I need to change the imports. So instead I want to use
from pyMS.test import *
However, this does not run any of the code. I’m curious for the reason why import * does not run the code.
Also, if someone knows a solution (that is note nose) to run all unittests without having to import them one by one would be great.
Thanks
Niek
If you use python 2.7 you can use the command line:
This will automatically find and execute all tests in all subdirectories. For more options, see:
This module has been backported to python 2.3+ and can be downloaded here. If you use the backport there’s an included command line script called unit2 or unit2.py (your choice), invoked like this:
As for
from XXX import *, this actually imports everything in the namespace of the fileXXX/__init__.py. Put the following code in__init__.pyto automatically load any direct submodules:A detailed explanation of how this works can be found in the python docs for the
__all__global variable.