[Tutor] Testing Frameworks and Organizations

Eike Welk eike.welk at gmx.net
Thu Apr 23 17:13:25 CEST 2009

Hello Spir; hello all!

I have a similar question:
For projects with multiple packages (directories) and modules (files); 
where do you put your testcode, what framework do you use, and what 
design patterns do you employ?

I currently work on a project with one package and several modules. I 
use the unittest module and my testcode is currently a mess. I use 
the following pattern:

------ start of file (module_n) -------------
import my_package.module_1 as module_1 
import my_package.module_2 as module_2

#module code goes here

if __name__ == '__main__':
    import unittest
    # Self-testing code goes here.
------ end of file -------------

Files structured like this can't be run as scripts, because the 
interpreter won't find the imported modules in the first two lines. 
However it works from my IDE (Eclipse) and this is the reason why I 
didn't bother to change the testcode's sorry state until now. 

I would really like to know how the Python experts organize their 
testcode, and what is considered the recommended way to do it. 

Kind regards,

More information about the Tutor mailing list